在Tweepy中使用SSL验证
去年,我用一个Python脚本来更新我的Twitter状态,但现在Twitter要求使用SSL验证,所以这个脚本出错了,错误信息是:
Tweepy.error.TweepError: [{'message': '需要SSL', 'code': 92}]
这个脚本非常简单,下面是代码。
# Consumer keys and access tokens, used for OAuth
consumer_key = 'type in your consumer key here'
consumer_secret = 'type in your consumer secret here'
access_token = 'type in your access token here'
access_token_secret = 'type in your access token secret here'
# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
# Creation of the actual interface, using authentication
api = tweepy.API(auth)
if len(sys.argv) >= 2:
tweet_text = sys.argv[1]
else:
tweet_text = "Still messing about with tweepy and twitter API. :)"
if len(tweet_text) <= 140:
api.update_status(tweet_text)
else:
print "tweet not sent. Too long. 140 chars Max."
任何帮助都非常感谢。谢谢。
3 个回答
0
试试这个。
auth.secure = True
这个对我有效!!!
0
试着把
api = tweepy.API(auth)
改成
api = tweepy.API(auth, secure=True)
这是Tweepy 2.2版本中的内容。
2
我之前也遇到过类似的问题,不过我通过从tweepy的GitHub页面安装tweepy解决了这个问题。
git clone https://github.com/tweepy/tweepy.git
python setup.py install
不过,很可能你正在尝试使用的项目是基于Twitter的REST API v1写的。因此,你可能会看到一个新的错误:
tweepy.error.TweepError: [{'message': 'Twitter的REST API v1已经不再使用了。请迁移到API v1.1。https://dev.twitter.com/docs/api/1.1/overview.', 'code': 64}]