Python: urlerror urlopen error unknown url type https 

Joined:
04/09/2007
Posts:
710

January 04, 2010 05:04:10    Last update: January 07, 2010 15:59:25
This is the error:
>>> import urllib2
>>> f = urllib2.urlopen('https://www.google.com')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/python-2.5/lib/python2.5/urllib2.py", line 121, in urlopen
    return _opener.open(url, data)
  File "/usr/local/python-2.5/lib/python2.5/urllib2.py", line 374, in open
    response = self._open(req, data)
  File "/usr/local/python-2.5/lib/python2.5/urllib2.py", line 397, in _open
    'unknown_open', req)
  File "/usr/local/python-2.5/lib/python2.5/urllib2.py", line 353, in _call_chain
    result = func(*args)
  File "/usr/local/python-2.5/lib/python2.5/urllib2.py", line 1134, in unknown_open
    raise URLError('unknown url type: %s' % type)
urllib2.URLError: <urlopen error unknown url type: https>
>>>


Reason: SSL is not supported in Python installation.
>>> import httplib
>>> hasattr(httplib, 'HTTPS')
False
>>> import socket
>>> hasattr(socket, 'ssl')
False
>>> import _ssl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named _ssl


Solution: recompile Python with SSL on

Steps:
  1. Download and install OpenSSL, if you don't have it already.
  2. Download Python source and rebuild Python (the usual steps of configure, make and make install). Python's configure script should be able to pick up your existing SSL libraries automatically and build a shared library _ssl.so.


Some web sites suggest editing the file Modules/setup.dist, uncomment the lines starting with _ssl, and making changes to the SSL path. This would link the SSL library statically to Python.

# Socket module helper for socket(2)
#_socket socketmodule.c

# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
#_ssl _ssl.c \
#   -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
#   -L$(SSL)/lib -lssl -lcrypto
Share |
| Comment  | Tags
 
Easy email testing with http://www.ximailstop.com