vizshine / python-twitter

Automatically exported from code.google.com/p/python-twitter
Apache License 2.0
0 stars 0 forks source link

twitterApi will return exception which are not twitter exceptions #240

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hi,

I run into the following problem. 
The twitter api says it will raise an twitter.exception if something goes 
wrong. Unfortunately also BadStatusLine-Exceptions will be raised as httplib 
will raise it and python-twitter will no handle it.
Here is a log from something like that occurring.

2012-09-26 23:45:04,505 [ERROR   ] 
Traceback (most recent call last):
  File "/harryplotter/harryplotter.py", line 69, in <module>
    tweets = get_tweets_by_terms(terms, last_id, tweets_per_page = config.getint("twitter", "tweets_per_page"), recursive = True)
  File "/harryplotter/harrytools.py", line 9, in get_tweets_by_terms
    tweets = get_tweets_by_term(term, last_id, refresh_time, tweets_per_page, recursive)
  File "/harryplotter/harrytools.py", line 24, in get_tweets_by_term
    tweets = twitter.Api().GetSearch(term=term, since_id=last_id, per_page=tweets_per_page, lang=None)
  File "/usr/local/lib/python2.6/dist-packages/python_twitter-0.8.2-py2.6.egg/twitter.py", line 2396, in GetSearch
    json = self._FetchUrl(url, parameters=parameters)
  File "/usr/local/lib/python2.6/dist-packages/python_twitter-0.8.2-py2.6.egg/twitter.py", line 3794, in _FetchUrl
    response = opener.open(url, encoded_post_data)
  File "/usr/lib/python2.6/urllib2.py", line 391, in open
    response = self._open(req, data)
  File "/usr/lib/python2.6/urllib2.py", line 409, in _open
    '_open', req)
  File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain
    result = func(*args)
  File "/usr/lib/python2.6/urllib2.py", line 1170, in http_open
    return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib/python2.6/urllib2.py", line 1143, in do_open
    r = h.getresponse()
  File "/usr/lib/python2.6/httplib.py", line 990, in getresponse
    response.begin()
  File "/usr/lib/python2.6/httplib.py", line 391, in begin
    version, status, reason = self._read_status()
  File "/usr/lib/python2.6/httplib.py", line 355, in _read_status
    raise BadStatusLine(line)
BadStatusLine

If this is expected behaviour, please document these or, as I prefer, catch it 
and return your own documented exception.

With best regards

pininety

Original issue reported on code.google.com by pinin...@googlemail.com on 27 Sep 2012 at 3:34

GoogleCodeExporter commented 9 years ago
Hi,
this is my first patch, so please be kind if I do something wrong.
I used the latest dev (tip was 189).
With best regards

pininety

Original comment by pinin...@googlemail.com on 9 Oct 2012 at 10:44

Attachments: