本地主机使用macOS 10.13 python 3.6 django 2.0.2
windowServer2012R2使用了django 2.0.2,python 3.4,iis,fastCGI
如果运行localhost
此屏幕截图enter image description here
并放置数据并发布
返回200连接成功enter image description here
但是窗口服务器运行不起作用css
此屏幕截图enter image description here
并放置数据并发布
异常JSON对象必须是str,而不是'bytes'
在json.loads(request.body)
django debug发布数据
_content_type
'application/json'
_content
('{\r\n'
' "UserEmail": "",\r\n'
' "UserPassword": "",\r\n'
' "UserSex": 1,\r\n'
' "UserAge": 1,\r\n'
' "DeviceId": "",\r\n'
' "PushKey": "",\r\n'
' "OS": 1,\r\n'
' "OSVersion": ""\r\n'
'}')
我认为这是编码问题,但我无法解决。
localhost
print(request.body)
结果
b'{\n "UserEmail": "",\n "UserPassword": "",\n "UserSex": 1,\n "UserAge": 1,\n "DeviceId": "",\n "PushKey": "",\n "OS": 1,\n "OSVersion": ""\n}'
windowserver
b'_content_type=application%2Fjson&_content=%7B%0D%0A++++%22UserEmail%22%3A+%22%22%2C%0D%0A++++%22UserPassword%22%3A+%22%22%2C%0D%0A++++%22UserSex%22%3A+1%2C%0D%0A++++%22UserAge%22%3A+1%2C%0D%0A++++%22DeviceId%22%3A+%22%22%2C%0D%0A++++%22PushKey%22%3A+%22%22%2C%0D%0A++++%22OS%22%3A+1%2C%0D%0A++++%22OSVersion%22%3A+%22%22%0D%0A%7D'
我试过json.loads(request.body.decode("utf-8"))
例外情况enter image description here
答案 0 :(得分:0)
尝试以下代码
import json
body_string = request.body.decode("utf-8", "ignore")
data = json.loads(body_string)
或者只是尝试
data = json.loads(request.data.get('_content'))