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

时间:2012-01-16 13:54:30

标签: python twitter

执行删除历史推文的python脚本时 我约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分钟后它总是会破坏....

1 个答案:

答案 0 :(得分:2)

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

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