Does urllib or urllib2 in Python 2.5 support https?
Thanks for the help in advance. I am puzzled that the same code works for python 2.6 but not 2.5. Here is the code
import cgi, urllib, urlparse, urllib2
url='https://graph.facebook.com'
req=urllib2.Request(url=url)
p=urllib2.urlopen(req)
response = cgi.parse_qs(p.read())
And here is the exception I got
Traceback (most recent call last):
File "t2.py", line 6, in <module>
p=urllib2.urlopen(req)
File "/home/userx/lib/python2.5/urllib2.py", line 124, in urlopen
return _opener.open(url, data)
File "/home/userx/lib/python2.5/urllib2.py", line 381, in open
response = self._open(req, data)
File "/home/userx/lib/python2.5/urllib2.py", line 404, in _open
'unknown_open', req)
File "/home/userx/lib/python2.5/urllib2.py", line 360, in _call_chain
result = func(*args)
File "/home/userx/lib/python2.5/urllib2.py", line 1140, in unknown_open
开发者_StackOverflow raise URLError('unknown url type: %s' % type)
urllib2.URLError: <urlopen error unknown url type: https>
Again, appreciate for help.
Most likely you're 2.5 version as been compiled without ssl support.
Try this :
>>> import socket
>>> socket.ssl
<function ssl at 0xb7ce602c>
to check if ssl is present (ie, you don't catch an AttributeError)
If you get
urllib2.URLError: <urlopen error unknown url type: https>
you have to install openssl, libssl-dev and rebuild python from sources
精彩评论