使用Tweepy进行SSL验证

时间:2014-03-17 22:31:00

标签: python ssl oauth tweepy

去年,我使用Python脚本来更新我的Twitter状态,但由于Twitter现在需要SSL验证,因此脚本失败并显示以下内容:

Tweepy.error.TweepError:[{'message':'SSL is required','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 :(得分:2)

我遇到了类似的问题,但设法通过从the tweepy GitHub repo安装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}]

答案 1 :(得分:0)

尝试更改

api = tweepy.API(auth)  

api = tweepy.API(auth, secure=True)  

这是在Tweepy的2.2版本中。

答案 2 :(得分:0)

试试这个。

auth.secure = True

这项工作对我来说!!!