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
urllib python2.6有SSL支持,您的代码示例对我来说很好。可能您的Python是在没有SSL支持的情况下构建的?尝试重新安装Python2.6(或更好的2.7)并使用 python.org .
urllib
在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)
要获得SSL支持,您需要使用编译Python OpenSSL . 例如,在ubuntulucid下,您必须安装模块libcurl4 openssl dev,然后重新构建Python。
尝试使用 urllib2 相反。
我在OSX10.6上使用macports中的Python2.6.6使用urllib时遇到了同样的问题。切换到urllib2修复了它。