【发布时间】:2017-07-01 08:31:49
【问题描述】:
查询以文本形式返回响应,我想以 json 格式获取它。
Python 3.5.3
import ssl
import json
import requests
url = 'https://127.0.0.1:8000/'
payload = json.dumps({'User':'Adam', 'Password':'123456'})
r = requests.post(url, data=payload)
回复:
In [23]: r.text
Out[23]: 'status=ok&info=00005'
In [24]: r.json()
Out[24]: JSONDecodeError: Expecting value: line 1 column 1 (char 0)
如何以 json 格式获取此数据,如下所示:
{
'status: 'ok',
'info': '00005'
}
【问题讨论】:
-
如果服务器应用程序在 localhost 上运行,假设您可以控制它,那么为什么不只返回 JSON?
-
服务器地址是我不控制它们的一个例子。服务器返回标头链接 'Content-Type': 'text/html;charset=UTF-8'
标签: python json python-3.x python-requests