模块' tweepy'没有属性' OAuthHandler'

时间:2017-01-29 02:23:49

标签: python twitter oauth twitter-oauth tweepy

所以我试图设置Tweepy,这样我就可以开始编程了。

我的第一个程序看起来如何:

#IMPORTING LIBRARIES
#    * tweepy - Twitter API

import tweepy


#LISTING CREDENTIALS

_consumer_key = 'MYCONSUMERKEY'
_consumer_secret = 'MYCONSUMERSECRETKEY'
_access_token = 'MYACCESSTOKEN'
_access_token_secret = 'MYACCESSTOKENSECRET'


#OAUTHHANDLER INSTANCE
#   * works over HTTP and authorizes devices, APIs, servers, and
#     applications — is a standard that provides secure and delegated access.

auth = tweepy.OAuthHandler(_consumer_key, _consumer_secret)
auth.set_access_token(_access_token, _access_token_secret)
auth.secure = True
api = tweepy.API(auth)

#UPDATE STATUS

tweet = "Hello, world!"
api.update_status(status=tweet)

当我运行它时,我收到以下错误:

auth = tweepy.OAuthHandler(_consumer_key, _consumer_secret)
AttributeError: module 'tweepy' has no attribute 'OAuthHandler'

我觉得这可能是因为我的文件结构,但是我一直在玩弄文件而没有运气。

1 个答案:

答案 0 :(得分:1)

尝试像这样导入:

from tweepy.auth import OAuthHandler
auth = OAuthHandler(_consumer_key, _consumer_secret)
auth.set_access_token(_access_token, _access_token_secret)

希望,它会有所帮助:)