我正在尝试使用Tweepy来使用Twitter流API,我正在关注文档(http://docs.tweepy.org/en/v3.5.0/auth_tutorial.html)。
但是,在页面上,我停留在http://docs.tweepy.org/en/v3.5.0/auth_tutorial.html
。它给了我错误name 'session' is not defined
。由于教程没有说明它正在使用哪个库,我无法继续。有人可以帮忙吗?
我的代码:
session.set('request_token', auth.request_token)
答案 0 :(得分:0)
We don't have your full code, but I would suspect that you haven't defined session in your code. If you haven't, you'll get a NameError error like the following (the same one you have):
NameError: name 'session' is not defined
When you try to call a variable that hasn't been defined, you get a name error. Session needs to be defined somewhere. On the other hand, in Tweepy's Streaming API there doesn't appear to be any similar examples or instructions.
In the Streaming with Tweepy section of the API documentation, it says you need an API object covered in the Authentication Tutorial. At the bottom of said tutorial, you create an API object like so:
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
api = tweepy.API(auth)
In the Streaming with Tweepy section of the documentation, you use the API object to create the stream:
myStreamListener = MyStreamListener()
myStream = tweepy.Stream(auth = api.auth, listener=myStreamListener())
Of course, you need to follow the additional instructions on the page to create the Stream Listener in step 1 of Streaming with Tweepy and to start the stream in step 3.