#!/usr/bin/env python # -*- coding: utf-8 -*- # @Time : 2022/1/26 13:29 # @Author : zyf # @description : def requse(): url = "http://vas.sh-test.xiaoyi.com/v2/api-docs" headers = {'Connection': 'close'} response = requests.get(url, headers=headers, ) # 发送get请求 # 获取信息乱码问题 msg 是原始的信息 """ 获取信息乱码问题 msg.decode('GBK', 'ignore') # bytes 转为 str str 转为 bytes msg.decode('utf-8', 'ignore').encode('utf-8') """ """ 把bytes 转化 hex() 16进制码 info = msg.hex() """ """ 把bytes 转化 str info = msg.decode('utf-8') """ """"" rite() argument must be str, not bytes ; bytes 是无法进行写入的文件的 """ rep = response.text.encode('GBK', 'ignore').decode('GBk') # rep =json.load(rep) # mm=rep.get('tags') print(rep) # 写入解决乱码问题 """ 写入解决乱码问题 """ with open('test.json', 'w', encoding='utf-8') as f: f.write(rep) time.sleep(3) return rep def te(): """ :return: """ """ 字典中的消息 """ false = False true = True response_content = {"result": false, "returnCode": "500", "message": "失败", "info": true} print(response_content, type(response_content)) if __name__ == '__main__': requse()
标签:转化,utf,字节,rep,bytes,乱码,msg,response From: https://www.cnblogs.com/zyf531/p/17041247.html