urllib.py doesn't work with https?

后端 未结 3 1902
醉梦人生
醉梦人生 2021-01-03 05:43

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\', \         


        
相关标签:
3条回答
  • 2021-01-03 06:13

    Try using urllib2 instead.

    I had the same issue with urllib on OSX 10.6 using python 2.6.6 from macports. Switching to urllib2 fixed it.

    0 讨论(0)
  • 2021-01-03 06:20

    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.

    0 讨论(0)
  • 2021-01-03 06:26

    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)
    
    0 讨论(0)
提交回复
热议问题