urllib.py无法与https一起使用?
发布于 2021-01-29 16:14:26
在我的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
关注者
0
被浏览
233
1 个回答
-
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)