tweepy Not Authorized - tweepy.error.TweepError: Not authorized

六月ゝ 毕业季﹏ 提交于 2020-01-03 10:54:51

问题


I get the following error when I try to use tweepy for twitter authentication.

  File "/usr/local/lib/python2.7/dist-packages/tweepy/models.py", line 146, in followers
    return self._api.followers(user_id=self.id, **kargs)
  File "/usr/local/lib/python2.7/dist-packages/tweepy/binder.py", line 197, in _call
    return method.execute()
  File "/usr/local/lib/python2.7/dist-packages/tweepy/binder.py", line 173, in execute
    raise TweepError(error_msg, resp)
tweepy.error.TweepError: Not authorized.

I am not building a web app. So, authentication is simpler.

consumer_key="----------"
consumer_secret="----------"
access_token="--------------"
access_token_secret="-----------------"

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

api.get_user('---').followers()

回答1:


Fixed. The particular user had protected tweets. Hence, .followers() was failing.




回答2:


I had a for that looped through my followers in order to get all their followers. And i got crashed with the same error. My workaround was:

try:
    api.get_user('---').followers()
    ...
except tweepy.TweepError:
    print("Failed to run the command on that user, Skipping...")

Although it makes you miss some of the users. My loop has successfully finished and got about 99% percent of my followers. So It is probably really rare that a user has protected tweets.



来源:https://stackoverflow.com/questions/19544401/tweepy-not-authorized-tweepy-error-tweeperror-not-authorized

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!