向Twitter API发送请求时出现500服务器错误

时间:2012-07-25 19:51:39

标签: python api twitter

我将以下请求发送到Twitter API,它收到以下错误:

http://search.twitter.com/search.json?q=feel%2BOR%2Bi%27m%2BOR%2Bi+am%2BOR%2Bim%2BOR%2Bmakes+me%2BOR%2Bmade+me%2BOR%2Bmaking+me%2BOR%2Bmaking+me+feel%2BOR%2Bmy+mood%2BOR%2Bi%27m+so%2BOR%2Bim+so&rpp=99&page=14

Traceback (most recent call last):
  File "C:\Users\andrew\Downloads\twitterthingv5test.py", line 95, in <module>
    moodParser()
  File "C:\Users\andrew\Downloads\twitterthingv5test.py", line 93, in moodParser
    query()
  File "C:\Users\andrew\Downloads\twitterthingv5test.py", line 37, in query
    main(columns)
  File "C:\Users\andrew\Downloads\twitterthingv5test.py", line 52, in main
    response = urllib2.urlopen(twiturl)
  File "C:\Python27\lib\urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "C:\Python27\lib\urllib2.py", line 400, in open
    response = meth(req, response)
  File "C:\Python27\lib\urllib2.py", line 513, in http_response
    'http', request, response, code, msg, hdrs)
  File "C:\Python27\lib\urllib2.py", line 438, in error
    return self._call_chain(*args)
  File "C:\Python27\lib\urllib2.py", line 372, in _call_chain
    result = func(*args)
  File "C:\Python27\lib\urllib2.py", line 521, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 500: Internal Server Error

我用来生成URL的代码是:

twiturl = "http://search.twitter.com/search.json?q=" + urlinfo + "&rpp=99&page=14"

发生了什么事?这会是一次发送太多请求的实例吗?

1 个答案:

答案 0 :(得分:0)

在第一次尝试时我也这样做,所以它可能不是速率限制。反复缩短查询:

这让我觉得这是对查询长度的限制。添加字母直到再次失败,这是单词mood的一部分:

然而,260个字符的查询字符串成功:

关于q参数的docs say

  

UTF-8,URL编码的搜索查询,最多1,000个字符,包括运算符。查询可能还会受到复杂性的限制。

奇怪的是,削减一半的单词算作额外的复杂性,但你去了。