【问题标题】:tweepy Not Authorized - tweepy.error.TweepError: Not authorizedtweepy 未授权 - tweepy.error.TweepError:未授权
【发布时间】:2013-11-01 21:20:53
【问题描述】:

当我尝试使用 tweepy 进行 twitter 身份验证时收到以下错误。

  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.

我不是在构建网络应用程序。因此,身份验证更简单。

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()

【问题讨论】:

    标签: twitter twitter-oauth tweepy


    【解决方案1】:

    已修复。特定用户拥有受保护的推文。因此,.followers() 失败了。

    【讨论】:

    • 已修复?在新版本中?我还在用 2.3.0
    • ``` except tweepy.TweepError as ex: if ex.reason == "Not authorized.": # do something here ```
    【解决方案2】:

    我有一个 for 循环遍历我的追随者,以吸引他们的所有追随者。我因同样的错误而崩溃。 我的解决方法是:

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

    虽然它会让你错过一些用户。我的循环已成功完成并获得了大约 99% 的关注者。因此,用户保护推文可能真的很少见。

    【讨论】:

      猜你喜欢
      • 2018-06-15
      • 2016-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 2011-04-21
      • 2022-08-24
      • 2019-02-16
      相关资源
      最近更新 更多