urllib.py不支持https?
在我的Python应用程序中,我尝试打开一个https的网址,但我遇到了以下问题:
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'
这是我的代码:
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
3 个回答
1
试试用 urllib2 来解决这个问题。
我在使用 macports 的 python 2.6.6 在 OSX 10.6 上也遇到过同样的问题。换成 urllib2 后就解决了。
6
要让Python支持SSL,你需要用OpenSSL来编译Python。举个例子,如果你使用的是ubuntu lucid系统,你需要先安装一个叫做libcurl4-openssl-dev的模块,然后再重新编译Python。
3
urllib
和Python 2.6支持SSL,你的代码示例在我这儿运行得很好。可能是你的Python版本没有SSL支持?试着重新安装Python 2.6(或者更好的是,安装2.7),并使用来自python.org的原版安装包。
在Google App Engine上,试着直接使用API:
from google.appengine.api import urlfetch
url = "https://www.google.com/"
result = urlfetch.fetch(url)
if result.status_code == 200:
doSomethingWithResult(result.content)