我只是得到了python的萦绕,我想开始使用它的API等。我安装了Tweepy,获取了我的Twitter密钥,然后在他们的网站上进行了安装过程。这是将细钱柜,好了,这里不明白Tweepy错误
import tweepy
auth = tweepy.OAuthHandler('qwertyuiop', 'asdfghjkl')
auth.set_access_token('qazsecftgbhujmkolp', 'plokmjuhbgtfcdeszaq')
api = tweepy.API(auth)
user = tweepy.api.get_user('twitter')
print user.screen_name
(与我的真实密钥,当然)
此方法返回的错误
Traceback (most recent call last):
File "tweeter.py", line 8, in <module>
user = tweepy.api.get_user('twitter')
File "/home/jeremiah/.local/lib/python2.7/site-packages/tweepy/binder.py", line 243, in _call
return method.execute()
File "/home/jeremiah/.local/lib/python2.7/site-packages/tweepy/binder.py", line 189, in execute
raise TweepError('Failed to send request: %s' % e)
tweepy.error.TweepError: Failed to send request: local variable 'auth' referenced before assignment
对此我只是不明白。定义auth
是我做的第一件事。此外,这是从网站的介绍课程。
看来这一切都很好,直到user = tweepy.api.get_user('twitter')
。如果我把它+下面的所有东西都拿出来,没关系,或者如果我用它来代替
public_tweets = api.home_timeline()
for tweet in public_tweets:
print tweet.text
这很好。
那是什么? Tweepy是否扭曲,是我的电脑扭曲,还是我只是失去了明显的东西?
感谢所有帮助
如果您取出'print user.screen_name',你确定没问题吗?看起来错误在'user = ...'行 – Claudiu
然而,它在'binder.py'中讨论'auth'对象的错误,不是你的。可能是一个问题,[见这里](https://github.com/tweepy/tweepy/blob/master/tweepy/binder.py#L173)。 – cdonts
@Claudiu是的,我搞砸了。编辑。 –