我正在使用python-sdk开发一些fb app。 有时我得到一个“未捕获的异常”,看起来像:
Uncaught exception GET… … … GraphAPIError: Error validating access token.
我知道这个例外的原因,以及如何解决它(更新oauth令牌)。
但我怎么能抓住它?
传统try: .. except:
不会这样做。
在不破解SDK代码的情况下寻找解决方案。
完整错误输出,如评论中所述:
[E 110407 20:44:20 web:900] Uncaught exception GET /fl?access_token=122385271170470|2.teD_D9DV6gegmpgkbZI_Hg__.3600.1302206400-1592301191|GuXEs4YTqsCPDNFU4fhbWuwlvOQ (127.0.0.1)
HTTPRequest(protocol='http', host='XX.XX.100.66', method='GET', uri='/fl?access_token=122385271170470|2.teD_D9DV6gegmpgkbZI_Hg__.3600.1302206400-1592301191|GuXEs4YTqsCPDNFU4fhbWuwlvOQ', version='HTTP/1.0', remote_ip='127.0.0.1', body='', headers={'Accept-Language': 'en-us,en;q=0.5', 'Accept-Encoding': 'gzip,deflate', 'X-Forwarded-For': '109.253.54.46', 'Host': 'XX.XX.100.66', 'Accept': 'application/json, text/javascript, */*', 'User-Agent': 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.16) Gecko/20110323 Ubuntu/10.10 (maverick) Firefox/3.6.16', 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'Connection': 'close', 'X-Requested-With': 'XMLHttpRequest', 'X-Real-Ip': 'XX.XX.54.46', 'Referer': 'http://XX.XX.100.66/'})
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/tornado-1.2-py2.6.egg/tornado/web.py", line 861, in _execute
getattr(self, self.request.method.lower())(*args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/tornado-1.2-py2.6.egg/tornado/web.py", line 941, in wrapper
return method(self, *args, **kwargs)
File "/home/blabla/src/python-sdk/examples/tornado/tornading.py", line 199, in get
self.render("json_output.html", json = json.dumps({"error":"login"}))
File "/usr/local/lib/python2.6/dist-packages/tornado-1.2-py2.6.egg/tornado/web.py", line 419, in render
html = self.render_string(template_name, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/tornado-1.2-py2.6.egg/tornado/web.py", line 520, in render_string
current_user=self.current_user,
File "/usr/local/lib/python2.6/dist-packages/tornado-1.2-py2.6.egg/tornado/web.py", line 683, in current_user
self._current_user = self.get_current_user()
File "/home/blabla/src/python-sdk/examples/tornado/tornading.py", line 109, in get_current_user
user = graph.get_object("me")
File "/home/blabla/src/python-sdk/src/facebook.py", line 88, in get_object
return self.request(id, args)
File "/home/blabla/src/python-sdk/src/facebook.py", line 179, in request
response["error"]["message"])
GraphAPIError: Error validating access token.
[E 110407 20:44:20 web:1235] 500 GET /fl?access_token=122385271170470|2.teD_D9DV6gegmpgkbZI_Hg__.3600.1302206400-1592301191|GuXEs4YTqsCPDNFU4fhbWuwlvOQ (127.0.0.1) 2714.20ms
尝试/除了代码:
try:
graph = facebook.GraphAPI(access_token)
except:
assert False, 'cougth it'