Closed GoogleCodeExporter closed 9 years ago
I added this code to API class, and replace the procedure above with a single
call to _Fetch_and_Check(), which takes the same arguments as _FetchUrl()
def _Fetch_and_Check(self,url,**kwargs):
"""Performs the FetchUrl and CheckForTwitterErrors in one call
Args:
url: the url to retrieve
All other kwargs the same as _Fetchurl()
Returns:
A json object, or raises a TwitterError
"""
json = self._FetchUrl(url,**kwargs)
self._CheckForCapcityError(json)
data = simplejson.loads(json)
self._CheckForTwitterError(data)
return data
def _CheckForCapictyError(self,json):
"""Raises a TwitterError if twitter returns a capcity error url
Args:
json : the json returned from a _FetchUrl call
Raises:
TwitterError("Capcity Error") if one exists
"""
if(re.search("<title>Twitter / Over capacity</title>",json)):
raise TwitterError("Capcity Error")
Original comment by adam.a...@gmail.com
on 27 Sep 2010 at 4:20
of course, spelling mistakes abound ... should be
_CheckForCapacityError()
Original comment by adam.a...@gmail.com
on 27 Sep 2010 at 4:32
I've discovered that there is another html error response that will cause a
value error, this one is differentiated by the title header "<title>Twitter /
Error</title>"
Here is a more robust form of what I suggested above:
def _Fetch_and_Check(self,url,**kwargs):
"""Performs the FetchUrl and CheckForTwitterErrors in one call
Args:
url: the url to retrieve
All other kwargs the same as _Fetchurl()
Returns:
A json object, or raises a TwitterError
"""
json = self._FetchUrl(url,**kwargs)
self._CheckForHTMLError(json)
try:
data = simplejson.loads(json)
except ValueError,e:
print >>sys.stderr, "Error in decoding"
print >>sys.stderr, json
print >>sys.stderr, "-"*10
traceback.print_exc()
raise TwitterError("json decoding")
self._CheckForTwitterError(data)
return data
def _CheckForHTMLError(self,json):
"""Raises a TwitterError if twitter returns a capcity error url
Args:
json : the json returned from a _FetchUrl call
Raises:
TwitterError("Capcity Error") if one exists
"""
if(re.search("<title>Twitter / Over capacity</title>",json,re.M)):
raise TwitterError("Capacity Error")
if(re.search("<title>Twitter / Error</title>",json,re.M)):
raise TwitterError("Techinical Error")
Original comment by adam.a...@gmail.com
on 28 Sep 2010 at 3:00
committed changeset 227:284cc18751db
Original comment by bear42
on 27 Feb 2011 at 5:58
Original issue reported on code.google.com by
adam.a...@gmail.com
on 27 Sep 2010 at 3:41Attachments: