python3 request json \ text \ content请求,解析返回字符为汉字

request返回:

  1. .json() 直接返回json数据,如果有汉字直接显示汉字;
  2. text , 字符串,如果有汉字需要编码转换;
  3. content,二进制,如果有汉字需要编码。
import requests,json

# url =r'http://127.0.0.1:8000/api/get_event_list/?eid={eid}&phone={phone}'
# eid = '1'
# phone = '1'
# client_request = requests.request(url=url.format(eid=eid,phone=phone),method='GET')
url =r'http://127.0.0.1:8000/api/get_event_list/'
p = {'eid':'1','phone':'1'}
client_request = requests.get(url=url,params=p)

content1 = client_request.json()
print(content1)
# {'status': 10000, 'message': '查询成功!', 'data': {'name': '小米发布会', 'limit': 10, 'status': True, 'address': '西二旗', 'start_time': '2019-04-01T06:20:12Z'}}

content2 = client_request.text
print(content2)
# {"status": 10000, "message": "\u67e5\u8be2\u6210\u529f!", "data": {"name": "\u5c0f\u7c73\u53d1\u5e03\u4f1a", "limit": 10, "status": true, "address": "\u897f\u4e8c\u65d7", "start_time": "2019-04-01T06:20:12Z"}}

content3 = client_request.text.encode('utf-8').decode('unicode_escape')
print(content3)
# {"status": 10000, "message": "查询成功!", "data": {"name": "小米发布会", "limit": 10, "status": true, "address": "西二旗", "start_time": "2019-04-01T06:20:12Z"}}

content4 = client_request.content
print(content4)
#b'{"status": 10000, "message": "\\u67e5\\u8be2\\u6210\\u529f!", "data": {"name": "\\u5c0f\\u7c73\\u53d1\\u5e03\\u4f1a", "limit": 10, "status": true, "address": "\\u897f\\u4e8c\\u65d7", "start_time": "2019-04-01T06:20:12Z"}}'

content5 = client_request.content.decode('unicode_escape')
print(content5)
#'{"status": 10000, "message": "查询成功!", "data": {"name": "小米发布会", "limit": 10, "status": true, "address": "西二旗", "start_time": "2019-04-01T06:20:12Z"}}'

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

生命的脚步从不停歇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值