接口测试-----打印响应函数实现
打印响应这个函数很常用,这里写一下
注意看 这里打印的res.content返回的结果是以b开头的,b开头说明这是一个字节串。 要转换成字符串需要进行解码 res.contetn.decode('utf-8')

 
用pprint美化输出
 1
def printResponse(self, response):
print('\n\n-------- HTTP response * begin -------')
print(response.status_code)
dict1=response.headers
for k, v in response.headers.items():
print(f'{k}: {v}')
if 'json' in dict1['Content-Type']:
pprint(response.json())
else:
pprint(response.content.decode('utf8'))
print('-------- HTTP response * end -------\n\n')
 
                     
                    
                 
                    
                 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号