增加判断响应体不为空才执行resp.json()

This commit is contained in:
shmilylty
2019-08-06 00:00:55 +08:00
parent 31666fdd75
commit 8420258ff7
+4 -6
View File
@@ -82,9 +82,8 @@ class Module(object):
if resp.status_code != 200 or not resp.content: # 状态码非200或者响应体为空
logger.log('ALERT', f'GET {resp.url} {resp.status_code} - {resp.reason} {len(resp.content)}')
content_type = resp.headers.get('Content-Type')
if content_type:
if 'json' in content_type:
logger.log('ALERT', resp.json())
if content_type and 'json' in content_type and not resp.content:
logger.log('ALERT', resp.json())
return None
logger.log('DEBUG', f'GET {resp.url} {resp.status_code} - {resp.reason} {len(resp.content)}')
return resp
@@ -106,9 +105,8 @@ class Module(object):
return None
if resp.status_code != 200 or not resp.content: # 状态码非200或者响应体为空
content_type = resp.headers.get('Content-Type')
if content_type:
if 'json' in content_type:
logger.log('ALERT', resp.json())
if content_type and 'json' in content_type and not resp.content:
logger.log('ALERT', resp.json())
return None
logger.log('DEBUG', f'POST {resp.url} {resp.status_code} - {resp.reason} {len(resp.content)}')
return resp