Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.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/6/rest/5.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
Python 处理来自http get调用的空响应_Python_Rest - Fatal编程技术网

Python 处理来自http get调用的空响应

Python 处理来自http get调用的空响应,python,rest,Python,Rest,我在self.method中有一个http get调用,在某些情况下,它在响应链接中只返回[]。我想用这个输出在另一个方法中处理异常,比如 if type(self.method()) is 'NoneType': print "The object is not present" else: self.method2() 我犯了错误 像 如何在if语句中捕获响应输出[]?假设在获取失败时self.method返回[]: 此代码段使用了这样一个事实,即隐式bool被强制转

我在self.method中有一个http get调用,在某些情况下,它在响应链接中只返回[]。我想用这个输出在另一个方法中处理异常,比如

if type(self.method()) is 'NoneType':
   print "The object   is  not  present"
else:
    self.method2()
我犯了错误 像

如何在if语句中捕获响应输出[]?

假设在获取失败时self.method返回[]:


此代码段使用了这样一个事实,即隐式bool被强制转换为响应,如果列表为空,则该响应的计算结果为False。它基本上是一个可读性更强的版本:if response=[]

您是来自JavaScript吗?进行此检查的python方法是self.method是否为None。或者如果self.method方法不能返回错误的值,如0、False或[]。非常感谢它的工作
AttributeError: 'Response' object has no attribute 'URL'
response = self.method()
if not response:
    print 'response missing'
else:
    do_things(reponse)