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

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