【问题标题】:GAE '_URLFetchResult' object has no attribute 'reason'GAE '_URLFetchResult' 对象没有属性 'reason'
【发布时间】:2015-10-22 01:11:38
【问题描述】:

我在 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

谁知道什么会导致这个错误?我什至尝试在请求中添加超时但没有改变任何东西。

【问题讨论】:

  • 这个例子是否完整? try 块中没有其他代码?异常是否有堆栈跟踪?您可以将其添加到问题中吗?您是在本地开发服务器上运行还是在 google 上运行?
  • @Alex 代码比这复杂得多,但我将问题缩小到这一行,我在谷歌上运行它。没有堆栈跟踪,将尝试获取更多信息

标签: python google-app-engine exception urlfetch


【解决方案1】:

试试这个:

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)

【讨论】:

  • 它不会在 HTTP 代码状态 200 上抛出异常,它通常会在没有响应因此没有状态代码,或者在 4XX http 状态代码的某个地方时这样做
猜你喜欢
  • 1970-01-01
  • 2019-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-01
相关资源
最近更新 更多