奇怪的python错误3分钟后,执行twitter脚本?

2024-10-02 16:29:17 发布

您现在位置:Python中文网/ 问答频道 /正文

当执行一个python脚本来获取历史tweet时 我大约2到3分钟后。得到以下错误!!!在

我真的不知道这意味着什么

我怎样才能阻止这一切发生

我在我的速率限制挑衅,因为在执行每个抓取循环之前,我检查,它返回为真!!!在

谢谢你的帮助

Traceback (most recent call last):
  File "twitter.py", line 13, in <module>
openurl = urllib.urlopen("https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&contributor_details&include_rts=true&screen_name="+user+"&count=3600")
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 84, in urlopen
return opener.open(url)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 205, in open
return getattr(self, name)(url)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 449, in open_https
return self.http_error(url, fp, errcode, errmsg, headers)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 369, in http_error
result = method(url, fp, errcode, errmsg, headers)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 691, in http_error_401
errcode, errmsg, headers)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib.py", line 379, in http_error_default
raise IOError, ('http error', errcode, errmsg, headers)
IOError: ('http error', 401, 'Unauthorized', <httplib.HTTPMessage instance at 0x1005ca9e0>)

脚本运行得很好,但2-3分钟后,它总是中断。。。。在


Tags: inpyhttpurlliblinelibraryframework
1条回答
网友
1楼 · 发布于 2024-10-02 16:29:17

Twitter的api有每小时150个查询的限制 https://dev.twitter.com/docs/rate-limiting 尝试在一个查询中查询多个tweet。 我想你的401回信会给你一个解释 试试这个

try:
    response = urllib2.urlopen.....
except urllib2.HTTPError as e:
    error = e.read() # this will be your error message
    print error

相关问题 更多 >