Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

urllib.py doesn't work with https?

In my python app I try to open a https url, but I get:

 File "C:\Python26\lib\urllib.py", line 215, in open_unknown
    raise IOError, ('url error', 'unknown url type', type)
IOError: [Errno url error] unknown url type: 'https'

my code:

import urllib
def generate_embedded_doc(doc_id):
    url = "https://docs.google.com/document/ub?id=" + doc_id + "&embedded=true"
    src = urllib.urlopen(url).read()
    ...
    return src
like image 765
Vladimir Keleshev Avatar asked Dec 29 '22 07:12

Vladimir Keleshev


2 Answers

To have SSL support you need to compile Python with OpenSSL. For example under ubuntu lucid you must install the module libcurl4-openssl-dev then re-build Python.

like image 179
axaroth Avatar answered Jan 05 '23 11:01

axaroth


urllib and Python 2.6 have SSL support and your code example works fine for me. Probably your Python is built without SSL support? Try to reinstall Python 2.6 (or better, 2.7) and use the original build from python.org.

On Google App Engine, try to use the API directly:

from google.appengine.api import urlfetch

url = "https://www.google.com/"
result = urlfetch.fetch(url)
if result.status_code == 200:
  doSomethingWithResult(result.content)
like image 43
leoluk Avatar answered Jan 05 '23 11:01

leoluk