Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python httplib2/oauth2查询Twitter API时发生SSL握手错误_Ssl_Twitter_Oauth 2.0_Httplib2 - Fatal编程技术网

使用Python httplib2/oauth2查询Twitter API时发生SSL握手错误

使用Python httplib2/oauth2查询Twitter API时发生SSL握手错误,ssl,twitter,oauth-2.0,httplib2,Ssl,Twitter,Oauth 2.0,Httplib2,我正在使用Ouath2对Python中的Twitter进行身份验证,并使用客户端对象查询Twitter API(这会自动对请求进行签名,这是httplib2的扩展) 以下是代码的简化版本: import oauth2 as oauth # authenticate consumer = oauth.Consumer(consumer_key, consumer_secret) token = oauth.Token(token_key, token_secret) client = oauth

我正在使用Ouath2对Python中的Twitter进行身份验证,并使用客户端对象查询Twitter API(这会自动对请求进行签名,这是httplib2的扩展)

以下是代码的简化版本:

import oauth2 as oauth

# authenticate
consumer = oauth.Consumer(consumer_key, consumer_secret)
token = oauth.Token(token_key, token_secret)
client = oauth.Client(consumer, token)

# request url
info, data = client.request('https://api.twitter.com/1.1/statuses/user_timeline.json?count=50&max_id=999999999999999999&screen_name=audiuk&since_id=643822673450168322', 'GET')
print data
在我的本地环境中,这可以正常工作,但在生产过程中,我会遇到以下错误:

2015-09-22 15:19:42 ERROR    SSLHandshakeError ([SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:581)) encountered for https://api.twitter.com/1.1/statuses/user_timeline.json?count=50&max_id=999999999999999999&screen_name=audiuk&since_id=643822673450168322, aborting
我正在使用Python 2.7.9


谢谢。

请升级httplib2

# pip install httplib2 --upgrade

在您部署的版本中,httplib2证书似乎已过期(我也遇到过这种情况)
如果您不想像我一样更新整个库,请尝试将cacerts.txt替换为

1-获取此文件的路径:

>>> import httplib2
>>> httplib2.__file__
'/usr/local/lib/python2.7/dist-packages/httplib2/__init__.pyc'
2-Mv进入目录并重命名旧的cacerts.txt

mv cacerts.txt cacerts.txt.old
3-获得新版本并享受oauth2带来的乐趣

wget https://raw.githubusercontent.com/jcgregorio/httplib2/master/python2/httplib2/cacerts.txt

你甚至可以用一句话来改进答案,说明为什么这会解决这个问题。。。