代码之家  ›  专栏  ›  技术社区  ›  Adam

Django+iis请求。身体问题

  •  0
  • Adam  · 技术社区  · 6 年前

    使用的本地主机是macOS 10.13 python 3.6 django 2.0.2

    WindowsServer2012R2使用django 2.0.2、python 3.4、iis、fastCGI

    如果我运行localhost,我有以下截图:

    enter image description here

    并将数据和post return 200连接成功:

    enter image description here

    但是CSS在窗口服务器上不起作用。

    此屏幕截图:

    enter image description here

    并将数据和后期制作:

    异常JSON对象必须是str,而不是“bytes” 在里面 json.loads(request.body)

    Django调试后期数据

    _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'
     '}')
    

    enter image description here

    我认为这是一个编码问题,但我不能解决它。

    本地服务器

    print(request.body)
    

    后果

    `b'{\n    "UserEmail": "",\n    "UserPassword": "",\n    "UserSex": 1,\n    "UserAge": 1,\n    "DeviceId": "",\n    "PushKey": "",\n    "OS": 1,\n    "OSVersion": ""\n}'`
    

    Windows服务器

    `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

    1 回复  |  直到 4 年前
        1
  •  0
  •   anjaneyulubatta505 Anshik    6 年前

    尝试以下代码

    import json
    
    body_string = request.body.decode("utf-8", "ignore")
    data = json.loads(body_string)
    

    或者试试看

    data = json.loads(request.data.get('_content'))