[Tutor] How to use urllib2.https_open with SSL support in Windows XP for python 2.5.2]
xbmuncher
xboxmuncher at gmail.com
Tue Aug 19 03:36:52 CEST 2008
I tried it just like both of you suggested and sent a req object straight to
urlopen. Here is my code:
import urllib2
url = 'https://url.com'
headers = {
'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)',
'Accept' :
'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
'Accept-Language' : 'fr-fr,en-us;q=0.7,en;q=0.3',
'Accept-Charset' : 'ISO-8859-1,utf-8;q=0.7,*;q=0.7'
}
#None = GET; set values to use POST
req = urllib2.Request(url, None, headers)
handle = urllib2.urlopen(req)
resp = handle.read()
print resp.geturl()
print resp.info()
print resp
resp.close()
Here is the error msg:
Traceback (most recent call last):
File "C:\Documents and Settings\user\Desktop\https_query.py", line 16, in
<module>
handle = urllib2.urlopen(req)
File "C:\Python25\lib\urllib2.py", line 124, in urlopen
return _opener.open(url, data)
File "C:\Python25\lib\urllib2.py", line 381, in open
response = self._open(req, data)
File "C:\Python25\lib\urllib2.py", line 399, in _open
'_open', req)
File "C:\Python25\lib\urllib2.py", line 360, in _call_chain
result = func(*args)
File "C:\Python25\lib\urllib2.py", line 1115, in https_open
return self.do_open(httplib.HTTPSConnection, req)
File "C:\Python25\lib\urllib2.py", line 1080, in do_open
r = h.getresponse()
File "C:\Python25\lib\httplib.py", line 928, in getresponse
response.begin()
File "C:\Python25\lib\httplib.py", line 385, in begin
version, status, reason = self._read_status()
File "C:\Python25\lib\httplib.py", line 349, in _read_status
raise BadStatusLine(line)
BadStatusLine
>>>
On Mon, Aug 18, 2008 at 4:57 PM, arsyed <arsyed at gmail.com> wrote:
> On Mon, Aug 18, 2008 at 4:25 PM, bob gailer <bgailer at gmail.com> wrote:
> > Forwarding to the list. Please always reply to the list.
> >
> > --
> > Bob Gailer
> > Chapel Hill NC 919-636-4239
> >
> > When we take the time to be aware of our feelings and needs we have more
> > satisfying interatctions with others.
> >
> > Nonviolent Communication provides tools for this awareness.
> >
> > As a coach and trainer I can assist you in learning this process.
> >
> > What is YOUR biggest relationship challenge?
> >
> >
> > I wanted to use the urllib2.https_open() but it said the module did not
> > exist. The manual says I need SSL support installed. I've done some
> > searching.. but I haven't been able to find an official implementation of
> > SSL support for python 2.5 for windows. If its required for urllib2 I
> assume
> > its part of the official python library of modules, is there an MSI
> > installer or official place to get the SSL support that was mentioned in
> the
> > urllib2 doc page? I just want to use the https capability of urllib2.
> >
> >
> > -thanks
> >
>
>
> Calling urlopen with an https scheme should be sufficient as long as
> python with SSL support is installed. I have the ActiveState Python
> 2.5.2 distribution on Windows XP and it seems to work fine:
>
> In [3]: response = urllib2.urlopen('https://google.com')
>
> In [4]: response = urllib2.urlopen('https://mail.google.com')
>
> In [5]: html = response.read()
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080818/493963f9/attachment-0001.htm>
More information about the Tutor
mailing list