urllib.py不适用于https? [英] urllib.py doesn't work with https?
本文介绍了urllib.py不适用于https?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
文件C:\Python26在我的python应用程序中,我试图打开一个https url,但是我得到: \lib\urllib.py,第215行,在open_unknown
提高IOError,('url error','unknown url type',type)
IOError:[Errno url error] unknown url type :'https'
我的代码:
导入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
和Python 2.6有SSL支持,您的代码示例正常工作为了我。你的Python可能没有SSL支持?尝试重新安装Python 2.6(或更高版本,2.7)并使用 python.org 中的原始版本。
在Google App Engine上,尝试直接使用API:
from google.appengine .api import urlfetch
$ b $ url =https://www.google.com/
result = urlfetch.fetch(url)
if result.status_code == 200:
doSomethingWithResult(result.content)
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
解决方案
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)
这篇关于urllib.py不适用于https?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文