python urllib2 urlopen无法打开https链接

时间:2014-11-14 09:39:17

标签: python https urllib2

我正在使用python编写一个oauth脚本。 当我尝试打开https链接“https://www.douban.com/service/auth2/token

它给出了以下错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/users/zhangxuan06/.jumbo/lib/python2.7/urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "/home/users/zhangxuan06/.jumbo/lib/python2.7/urllib2.py", line 400, in open
    response = self._open(req, data)
  File "/home/users/zhangxuan06/.jumbo/lib/python2.7/urllib2.py", line 418, in _open
    '_open', req)
  File "/home/users/zhangxuan06/.jumbo/lib/python2.7/urllib2.py", line 378, in _call_chain
    result = func(*args)
  File "/home/users/zhangxuan06/.jumbo/lib/python2.7/urllib2.py", line 1215, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "/home/users/zhangxuan06/.jumbo/lib/python2.7/urllib2.py", line 1177, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 110] Connection timed out>

但是当我用浏览器打开这个链接时,它工作正常并给我回复消息。

任何人都可以帮我吗? THX

更新:我的代码很简单

import urllib2,json
url = 'https://www.douban.com/service/auth2/token'
res = urllib2.urlopen(url)
print json.loads(res.read())

0 个答案:

没有答案