python - requests提交的json.dumps不能被服务器解析
巴扎黑
巴扎黑 2017-04-18 10:27:08
0
2
664

背景:
现有一看上去是内嵌IE应用程序A,可以做一些查询等操作。

目的:
通过借助Wireshark对应用程A的通信过程分析,借助python的requests的库自行构造一个自己能掌控的程序B

状况:
在使用requests库,加载json格式的POST数据,执行特定请求时,遇到对方服务器的报错。

payload_data={"jsonstr":{ "pagesize":10, "pageindex":1, "start":"2017-03-01", "end":"2017-03-13", "keyword":"张三", "status":"0" } } r = requests.post(url, headers = headers_comm, data = json.dumps(payload_data))

Wireshark对程序A请求的侦听:

自行构造请求时的报错信息:

猜测这个请求的构造基本成功了,但对端应用程序解析我POST的数据时不能正常识别。
尝试过给json.dumps加, ensure_ascii=False的参数,但报错依旧。
如果这个猜测正确的话,POST数据应该怎样正确dumps?
如果这个猜测不正确,那么可能是哪里的原因?

巴扎黑
巴扎黑

reply all (2)
小葫芦

Data does not require json.dump. You only need to use json.dump to include the following jsonstr in data. It should be like this, you can try it

    洪涛

    Response CodeIt’s 500. It’s because the other party made an error during deserialization.
    According to the exception information, the server should deserialize in the following way.

    C#:

    var jsonObj = (new JavaScriptSerializer()).Deserialize>(jsonString);

    Yourpayload_dataformat is wrong, it is a nested dictionary.

    Changepayload_datato:
    Python:

    payload_data={ "pagesize":10, "pageindex":1, "start":"2017-03-01", "end":"2017-03-13", "keyword":"张三", "status":"0" }

    That’s it.

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!