我正在尝试使用python和tweepy编写一个简单的twitter机器人,以使用twitter API编写twitter数据。代码如下
import csv
import tweepy
import argparse
import pandas as pd
####input your credentials here
consumer_key = '************************'
consumer_secret = '**************************************'
access_token = '**************************************'
access_token_secret = '***************************************'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth,wait_on_rate_limit=True
# Open/Create a file to append data
csvFile = open('result1.csv', 'a')
#Use csv Writer
csvWriter = csv.Writer(csvFile)
for tweet in tweepy.Cursor(api.search,q="#Russia",count=100,
lang="en",
since="2017-04-03").items():
print (tweet.created_at, tweet.text)
107 if self.index >= len(self.results) - 1:
--> 108 data = self.method(max_id=self.max_id, parser=RawParser(), *self.args, **self.kargs)
109
110 if hasattr(self.method, '__self__'):
D:\anaconda3\lib\site-packages\tweepy\binder.py in _call(*args, **kwargs)
248 return method
249 else:
--> 250 return method.execute()
251
252 # Set pagination mode
D:\anaconda3\lib\site-packages\tweepy\binder.py in execute(self)
232 raise RateLimitError(error_msg, resp)
233 else:
--> 234 raise TweepError(error_msg, resp, api_code=api_error_code)
235
236 # Parse the response payload
TweepError: Twitter error response: status code = 400
我期望的是在我的根文件夹中有一个CSV文件,但是CSV文件为空,因为代码运行不正常。我确实尝试过这些选项,但看不出任何区别。