How to open https Site and pass request?

Nico Grubert nicogrubert at gmail.com
Tue May 23 07:32:54 EDT 2006


Hi there,

I am trying to open an https site and pass a request to it in order to 
simulate the submit of an HTML form on a https site that sets an 
authentication cookie for a tomcat application, so the the URL I am 
trying to open points to a web form provided by the tomcat webserver.

I tried (Python 2.3.5):

 >>> import urllib
 >>> import urllib2
 >>> the_url = "https://myserver/application/login.do"
 >>> user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
 >>> headers = { 'User-Agent' : user_agent }
 >>> values = { 'username' : 'myuser', 'password' : 'mypasswd' }
 >>> data = urllib.urlencode(values)
 >>> req = urllib2.Request(the_url, data)
 >>> handle = urllib2.urlopen(req)

This raises the following exception:

Traceback (most recent call last):
   File "<stdin>", line 1, in ?
   File "/usr/local/lib/python2.3/urllib2.py", line 129, in urlopen
     return _opener.open(url, data)
   File "/usr/local/lib/python2.3/urllib2.py", line 331, in open
     'unknown_open', req)
   File "/usr/local/lib/python2.3/urllib2.py", line 306, in _call_chain
     result = func(*args)
   File "/usr/local/lib/python2.3/urllib2.py", line 914, in unknown_open
     raise URLError('unknown url type: %s' % type)
urllib2.URLError: <urlopen error unknown url type: https>


Any idea, what I did wrong?

Regards,
Nico



More information about the Python-list mailing list