Tweepy: tweepy.error.tweeperror 'code' 215 'message' 'bad authentication data.'
Tweepy: tweepy.error.tweeperror 'code' 215 'message' 'bad authentication data.'
我不确定这里出了什么问题。以下代码在 2 天前一直有效。我在 jupyter notebook
中的 python3
上使用 tweepy
版本号 3.6.0
。现在,当我执行下面给出的代码时,我不断收到错误 TweepError: [{'code': 215, 'message': 'Bad Authentication data.'}]
。我究竟做错了什么?我已经看过类似的帖子 1, 2,3,,5 and 6 但没有解决方案。请注意,我也重新生成了密钥,但错误仍然存在。
密码是;
import tweepy
ckey = 'xxx'
csecret = 'xxx'
atoken = 'xxx'
asecret = 'xxx'
# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
# Creation of the actual interface, using authentication
api = tweepy.API(auth)
# collect tweets on #MRT
for tweet in tweepy.Cursor(api.search,q="MRT",count=100,
lang="en",rpp=100,
since="2017-04-03").items():
print (tweet.created_at, tweet.text)
执行此代码时returns出现以下错误,
---------------------------------------------------------------------------
TweepError Traceback (most recent call last)
<ipython-input-11-b3e4ffb2d94f> in <module>()
2 for tweet in tweepy.Cursor(api.search,q="MRT",count=100,
3 lang="en",rpp=100,
----> 4 since="2017-04-03").items():
5 print (tweet.created_at, tweet.text)
~\Miniconda3\lib\site-packages\tweepy\cursor.py in __next__(self)
47
48 def __next__(self):
---> 49 return self.next()
50
51 def next(self):
~\Miniconda3\lib\site-packages\tweepy\cursor.py in next(self)
195 if self.current_page is None or self.page_index == len(self.current_page) - 1:
196 # Reached end of current page, get the next page...
--> 197 self.current_page = self.page_iterator.next()
198 self.page_index = -1
199 self.page_index += 1
~\Miniconda3\lib\site-packages\tweepy\cursor.py in next(self)
106
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__'):
~\Miniconda3\lib\site-packages\tweepy\binder.py in _call(*args, **kwargs)
248 return method
249 else:
--> 250 return method.execute()
251
252 # Set pagination mode
~\Miniconda3\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
任何建议都会有所帮助。
我复制了您的代码并在我的系统中执行了它,但没有发现任何错误。我正在使用 tweepy 3.6.0
和 Python 3.5.2
。我对您的代码进行了两次编辑。
import tweepy
ACCESS_TOKEN = "#####"
ACCESS_TOKEN_SECRET = "#####"
CONSUMER_KEY = "####"
CONSUMER_SECRET = "#####"
# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
# Creation of the actual interface, using authentication
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
# collect tweets on #MRT
for tweet in tweepy.Cursor(api.search,q="MRT",count=100,
lang="en",rpp=100).items():
print (tweet.created_at, tweet.text)
注意两个参数 tweepy.API
:wait_on_rate_limit
和 wait_on_rate_limit_notify
。 如果你想继续推文流,这两个参数很重要,因为 search
API 只给你 certain amount of tweets per request .
你有一个TweepError
with status code 400
。根据文档,它说:
The request was invalid or cannot be otherwise served. An accompanying error message will explain further. Requests without authentication are considered invalid and will yield this response.
一个可能的解释是您的 twitter API keys
不再进行身份验证,因为您一直在请求 超出 twitter[=38 的速率限制=].
希望这对您有所帮助。
我用双引号解决了问题,我看到你用的是单引号
CONSUMER_KEY = "xxx";
我遇到了同样的问题。重新生成密钥和令牌解决了问题。
我不确定这里出了什么问题。以下代码在 2 天前一直有效。我在 jupyter notebook
中的 python3
上使用 tweepy
版本号 3.6.0
。现在,当我执行下面给出的代码时,我不断收到错误 TweepError: [{'code': 215, 'message': 'Bad Authentication data.'}]
。我究竟做错了什么?我已经看过类似的帖子 1, 2,3,
密码是;
import tweepy
ckey = 'xxx'
csecret = 'xxx'
atoken = 'xxx'
asecret = 'xxx'
# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
# Creation of the actual interface, using authentication
api = tweepy.API(auth)
# collect tweets on #MRT
for tweet in tweepy.Cursor(api.search,q="MRT",count=100,
lang="en",rpp=100,
since="2017-04-03").items():
print (tweet.created_at, tweet.text)
执行此代码时returns出现以下错误,
---------------------------------------------------------------------------
TweepError Traceback (most recent call last)
<ipython-input-11-b3e4ffb2d94f> in <module>()
2 for tweet in tweepy.Cursor(api.search,q="MRT",count=100,
3 lang="en",rpp=100,
----> 4 since="2017-04-03").items():
5 print (tweet.created_at, tweet.text)
~\Miniconda3\lib\site-packages\tweepy\cursor.py in __next__(self)
47
48 def __next__(self):
---> 49 return self.next()
50
51 def next(self):
~\Miniconda3\lib\site-packages\tweepy\cursor.py in next(self)
195 if self.current_page is None or self.page_index == len(self.current_page) - 1:
196 # Reached end of current page, get the next page...
--> 197 self.current_page = self.page_iterator.next()
198 self.page_index = -1
199 self.page_index += 1
~\Miniconda3\lib\site-packages\tweepy\cursor.py in next(self)
106
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__'):
~\Miniconda3\lib\site-packages\tweepy\binder.py in _call(*args, **kwargs)
248 return method
249 else:
--> 250 return method.execute()
251
252 # Set pagination mode
~\Miniconda3\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
任何建议都会有所帮助。
我复制了您的代码并在我的系统中执行了它,但没有发现任何错误。我正在使用 tweepy 3.6.0
和 Python 3.5.2
。我对您的代码进行了两次编辑。
import tweepy
ACCESS_TOKEN = "#####"
ACCESS_TOKEN_SECRET = "#####"
CONSUMER_KEY = "####"
CONSUMER_SECRET = "#####"
# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
# Creation of the actual interface, using authentication
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
# collect tweets on #MRT
for tweet in tweepy.Cursor(api.search,q="MRT",count=100,
lang="en",rpp=100).items():
print (tweet.created_at, tweet.text)
注意两个参数 tweepy.API
:wait_on_rate_limit
和 wait_on_rate_limit_notify
。 如果你想继续推文流,这两个参数很重要,因为 search
API 只给你 certain amount of tweets per request .
你有一个TweepError
with status code 400
。根据文档,它说:
The request was invalid or cannot be otherwise served. An accompanying error message will explain further. Requests without authentication are considered invalid and will yield this response.
一个可能的解释是您的 twitter API keys
不再进行身份验证,因为您一直在请求 超出 twitter[=38 的速率限制=].
希望这对您有所帮助。
我用双引号解决了问题,我看到你用的是单引号
CONSUMER_KEY = "xxx";
我遇到了同样的问题。重新生成密钥和令牌解决了问题。