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

问题描述 投票:0回答:1

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

我觉得这可能是因为我的文件结构,但我已经玩弄了移动文件而没有运气。

python twitter oauth twitter-oauth tweepy
1个回答
1
投票

尝试像这样导入:

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

希望,它会有所帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.