我刚开始使用Tweepy,我一直在尝试执行youtube教程中的这一行代码,但是一直都有错误。有人知道怎么回事吗?这是我的密码
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’在赋值前引用
发布于 2018-06-28 02:45:42
这是在发出任何类型的API请求之前应该具有的基本设置结构:
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)然后你可以尝试这样的方法:
tweet = api.search(q="IPython")然后,如果您想打印推特的文本:
t = tweet.text
print(t)https://stackoverflow.com/questions/41751912
复制相似问题