首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Tweepy出错

Tweepy出错
EN

Stack Overflow用户
提问于 2017-01-19 21:20:55
回答 1查看 1.4K关注 0票数 0

我刚开始使用Tweepy,我一直在尝试执行youtube教程中的这一行代码,但是一直都有错误。有人知道怎么回事吗?这是我的密码

代码语言:javascript
复制
import tweepy
from tweepy import OAuthHandler

auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)

api = tweepy.API(auth)

res = api.search(q="IPython")

错误:

回溯(最近一次调用):文件"/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tweepy/binder.py",第186行,在执行auth=auth中,UnboundLocalError:赋值前引用的局部变量'auth‘

在处理上述异常的过程中,发生了另一个异常:

回溯(最近一次调用):文件"/Users/christopherdimitrisastropranoto/Desktop/twitterAnalysis/Listener.py",第22行,在趋势= trial.trends_place(1)文件"/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tweepy/binder.py",第245行中,在_call返回method.execute()文件"/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/tweepy/binder.py",中第189行,在执行引发TweepError(‘未能发送请求:%s’‘% e) tweepy.error.TweepError:未能发送请求:局部变量'auth’在赋值前引用

EN

回答 1

Stack Overflow用户

发布于 2018-06-28 02:45:42

这是在发出任何类型的API请求之前应该具有的基本设置结构:

代码语言:javascript
复制
import tweepy

consumer_key = "X-U" #this you get when you make create an application on twitter as a dev
consumer_secret = "Z" #this you get when you make create an application on twitter as a dev

acess_token = "Y-V" #this you get when you make create an application on twitter as a dev
acess_token_secret = "P" #this you get when you make create an application on twitter as a dev


auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(acess_token, acess_token_secret)

api = tweepy.API(auth, wait_on_rate_limit=True)

然后你可以尝试这样的方法:

代码语言:javascript
复制
tweet = api.search(q="IPython")

然后,如果您想打印推特的文本:

代码语言:javascript
复制
t = tweet.text
print(t)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41751912

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档