gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 13:16:43 24 4
gpt4 key购买 nike

我正在使用 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 证书似乎已过期(我也遇到过)
如果您不想像我一样更新整个库,请尝试将 cacerts.txt 替换为 last version

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

关于使用 Python httplib2/oauth2 查询 Twitter API 时出现 SSL 握手错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32723197/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com