Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在GAE上捕获Python中的DNSLookupFailedError?_Python_Google App Engine_Error Handling_Dns_Urlfetch - Fatal编程技术网

如何在GAE上捕获Python中的DNSLookupFailedError?

如何在GAE上捕获Python中的DNSLookupFailedError?,python,google-app-engine,error-handling,dns,urlfetch,Python,Google App Engine,Error Handling,Dns,Urlfetch,我测试使用urlfetch的人提供的URL以捕获错误的链接 result = urlfetch.fetch(url) 当我提供一个URL,如«http://qwerty.uiop»日志显示存在«DNSLookupFailedError»,但此代码无法捕获它: except urlfetch.DNSLookupFailedError: self.error(400) self.response.out.write( 'Sorry, there was a problem with URL "

我测试使用urlfetch的人提供的URL以捕获错误的链接

result = urlfetch.fetch(url)
当我提供一个URL,如«http://qwerty.uiop»日志显示存在«DNSLookupFailedError»,但此代码无法捕获它:

except urlfetch.DNSLookupFailedError:
self.error(400)
self.response.out.write(
  'Sorry, there was a problem with URL "' + url + '"')
我还尝试了“除urlfetch.Error:”和“除urlfetch.DownloadError:”


我做错了什么,还有其他方法来完成我想做的吗?

在本地开发人员环境和生产环境中,我实际上看到了一个不同的例外:
下载错误
。抓住它对我来说很好

try:
  result = urlfetch.fetch('http://qwerty.uiop')
except urlfetch.DownloadError:
  self.response.write('Oops!')

我无法复制你得到的东西,因为我没有本地的开发环境——我在iPad上进行开发。但这并不能解决生产环境中的问题。它仍然说:raise DNSLookupFailedError('URL:'+URL的DNS查找失败)DNSLookupFailedError:URL的DNS查找失败:是否有其他方法来完成我尝试的操作?我只在python和GAE上呆了三天,所以我经常沉迷于这些小事情。我不确定我是否理解你所说的没有本地开发环境是什么意思。App Engine SDK附带一个本地开发环境dev_appserver.py(或Mac launcher)。您是否使用在线课程进行开发?如果是这样,他们的环境可能会在常规生产环境的基础上增加额外的行为。然后我直接在GAE上测试我的代码——我称之为上面的生产环境,这可能是我的错误。因此,这里从来就没有什么地方环境。很抱歉我说得不够清楚。这仍然是我使用的相同的生产环境(谷歌的服务器)。您使用的SDK版本是什么?