GAE'_URLFetchResult'对象没有属性'reason'

时间:2015-10-22 01:11:38

标签: python google-app-engine exception urlfetch

我在GAE上使用python。以下是示例代码:

try:
   response = urlfetch.fetch(url, headers=headers)
except Exception, E:
   logging.error("urlfetch failed: %s: %s" %(E, E.__dict__))

对于某些请求,我得到了这个:

urlfetch failed: '_URLFetchResult' object has no attribute 'reason': {}

2011年有一个类似的问题并没有真正解决我的问题:Why am I getting an AttributeError when trying to print out

任何人都知道可能导致此错误的原因是什么?我甚至尝试在请求中添加超时但没有改变任何内容。

1 个答案:

答案 0 :(得分:0)

试试这个:

try:
   fetch_response = urlfetch.fetch(url, headers=headers)
except:
   logging.error("urlfetch failed. Status code: %d"  % (fetch_response.status_code))
   if fetch_response.status_code == 200:
       logging.error("fetch_response.content:")
       logging.error(fetch_response.content)