【问题标题】:Trying to access the Twitter API returns AttributeError: 'module' object has no attribute 'oauth'尝试访问 Twitter API 返回 AttributeError: 'module' object has no attribute 'oauth'
【发布时间】:2021-03-04 05:29:06
【问题描述】:

为什么我尝试访问 Twitter API 时会出现以下错误?

AttributeError Traceback(最近调用 最后)在() 17 18 ---> 19 auth = twitter.oauth.OAuth(access_token_key,access_token_secret,consumer_key,consumer_secret) 20 #twitter = twitter.Twitter(auth=twitter.oauth.OAuth(access_token_key,access_token_secret,consumer_key,consumer_secret)) 21 twitter_api = twitter.Twitter(auth=auth)

AttributeError: 'module' 对象没有属性 'oauth'

我的代码:

import twitter
#from twitter import *
#from twitter import oauth

consumer_key = ''
consumer_secret =''
access_token_key = ''
access_token_secret = ''

auth = twitter.oauth.OAuth(access_token_key,access_token_secret,consumer_key,consumer_secret)
#twitter = twitter.Twitter(auth=twitter.oauth.OAuth(access_token_key,access_token_secret,consumer_key,consumer_secret))
twitter_api = twitter.Twitter(auth=auth)

print twitter

【问题讨论】:

    标签: twitter oauth python-twitter


    【解决方案1】:

    我会仔细阅读他们的documentation

    从我提到的链接:

    from twitter import *
    
    t = Twitter(
        auth=OAuth(token, token_key, con_secret, con_secret_key))
    

    所以你看到auth=OAuth 不是auth=oauth.OAuth

    在你的情况下,你有import twitter,唯一的区别是你需要在每个属性之前添加twitter,但你仍然不需要oauth

    import twitter 
    
    t = twitter.Twitter(
        auth=twitter.OAuth(token, token_key, con_secret, con_secret_key))
    

    【讨论】:

      【解决方案2】:

      除了上面的答案,还要确保你已经做了-

      pip install oauth
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-09-26
        • 1970-01-01
        • 2014-12-20
        • 2022-12-01
        • 2022-12-01
        • 2012-02-29
        • 2013-07-26
        • 2014-03-23
        相关资源
        最近更新 更多