module 'tweepy' has no attribute 'OAuthHandler'

余生颓废 提交于 2019-12-12 06:29:14

问题


So I'm trying to set up Tweepy so I can start programming with it.

How my first program looks:

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

When I run this, I get the following error:

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

I feel it could be because of my file structure, but I have played around with moving files around with no luck.


回答1:


Try import like this:

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

Hope, it will help :)



来源:https://stackoverflow.com/questions/41917038/module-tweepy-has-no-attribute-oauthhandler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!