模块“tweepy"没有属性“OAuthHandler" [英] module 'tweepy' has no attribute 'OAuthHandler'

查看:52
本文介绍了模块“tweepy"没有属性“OAuthHandler"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在尝试设置 Tweepy,以便我可以开始使用它进行编程.

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.

推荐答案

尝试这样导入:

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

希望会有所帮助:)

这篇关于模块“tweepy"没有属性“OAuthHandler"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆