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

module 'tweepy' has no attribute 'OAuthHandler'

所以我正在尝试设置 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'

我觉得这可能是因为我的文件结构,但我一直在尝试移动文件,但没有成功。

尝试像这样导入:

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

希望,它会有所帮助:)