吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1519|回复: 8
收起左侧

[求助] 如何利用python的优势巧妙的组装POST-data提交的数据?

[复制链接]
删掉丶关于n1 发表于 2019-10-12 17:38
上一条返回来的内容:[{"statusCode":200,"type":"rpc","tid":2,"ref":false,"action":"ICS_WR_Warranty_Create_Agent_Controller","method":"calPMFTSystem","result":{"BoxTrayIndicator":"Boxed","Error":"false","Last_Ship_To_Date":"2017-05-25 00:00:00","ProductFrequencyData":[{"FreqeuncyCount":1,"FrequencyType":"ATPO"}],"ShipmentInfo":[{"AGIDDate":"2017-05-25T01:42:11-07:00","Batch":"L709C055","BoxTrayIndicator":"BOX","ChildBoxId":"804327398","Level4Prod":"BX80677I77700K","MaterialMasterNumber":"953655","ShipToCustomerCountryCode":"NL","ShipToCustomerCountryName":"Netherlands","ShipToCustomerGeo":"EMEA","VisualId":"U7NH442803139"}],"ValIDAtionResultCodes":[{"Remarks":" ","ValidationResult_Code":"PMFT-028","ValidationResultCodeId":28},{"Remarks":"","ValidationResult_Code":"PMFT-027","ValidationResultCodeId":27},{"Remarks":"","ValidationResult_Code":"PMFT-035","ValidationResultCodeId":35},{"Remarks":" ","ValidationResult_Code":"PMFT-015","ValidationResultCodeId":15},{"Remarks":"","ValidationResult_Code":"PMFT-034","ValidationResultCodeId":34}]}}]

下一条准备提交的内容:
{"action":"ICS_WR_Warranty_Create_Agent_Controller","method":"doWarrantyCheckProcessor","data":["{\"BoxTrayIndicator\":\"Boxed\",\"Error\":\"false\",\"Last_Ship_To_Date\":\"2017-05-25 00:00:00\",\"ProductFrequencyData\":[{\"FreqeuncyCount\":1,\"FrequencyType\":\"ATPO\"}],\"ShipmentInfo\":[{\"AGIDDate\":\"2017-05-25T01:42:11-07:00\",\"Batch\":\"L709C055\",\"BoxTrayIndicator\":\"BOX\",\"ChildBoxId\":\"804327398\",\"Level4Prod\":\"BX80677I77700K\",\"MaterialMasterNumber\":\"953655\",\"ShipToCustomerCountryCode\":\"NL\",\"ShipToCustomerCountryName\":\"Netherlands\",\"ShipToCustomerGeo\":\"EMEA\",\"VisualId\":\"U7NH442803139\"}],\"ValidationResultCodes\":[{\"Remarks\":\" \",\"ValidationResult_Code\":\"PMFT-028\",\"ValidationResultCodeId\":28},{\"Remarks\":\"\",\"ValidationResult_Code\":\"PMFT-027\",\"ValidationResultCodeId\":27},{\"Remarks\":\"\",\"ValidationResult_Code\":\"PMFT-035\",\"ValidationResultCodeId\":35},{\"Remarks\":\" \",\"ValidationResult_Code\":\"PMFT-015\",\"ValidationResultCodeId\":15},{\"Remarks\":\"\",\"ValidationResult_Code\":\"PMFT-034\",\"ValidationResultCodeId\":34}]}","{\"validateMainLineItem\":1000,\"validateProductId\":\"01t0P0000026L2QQAU\",\"validateProductType\":\"Processor\",\"strFpoNumber\":\"L709C055\",\"strAtpoNumber\":\"U7NH442803139\",\"mmid\":\"953655\"}","953655","BX80677I77700K","","",false],"type":"rpc","tid":3,"ctx":{"csrf":"VmpFPSxNakF4T1MweE1DMHhOVlF3T1Rvd05Eb3dPQzQwTVRaYSw3VTNjM0NiYmJ4ellWSXBEeTRPbGhOLE9UZzBOV1Zt","vid":"0660P000000yK7w","ns":"","ver":38}}

如何利用python的优势巧妙的组装成一个POST-DATA提交的数据?利用的是requests库
目前遇到的问题就是:提交的时候data参数里的引号需要带\"  我用json组装完之后 就没有 \"  导致提交失败  以上是完整提交的内容!

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

ghoob321 发表于 2019-10-12 17:45
占个沙发。这个没学过。
wuwuxin123 发表于 2019-10-12 17:46
绝版durex 发表于 2019-10-12 17:52
没记错的话 requests.post 中的data参数可以直接传入Python的字典 请求时会自动转换  不需要手动处理
super.single430 发表于 2019-10-12 18:04
requests.post(url, data=json.dumps(data)) ?
 楼主| 删掉丶关于n1 发表于 2019-10-12 18:08
super.single430 发表于 2019-10-12 18:04
requests.post(url, data=json.dumps(data)) ?

准备提交的内容是通过上条数据返回的内容进行组装提交  比如data是上一条的数据获取的
SGC沉默 发表于 2019-10-12 19:37
序列化json就行
1170 发表于 2019-10-12 19:38
先把上条数据返回下次需要提交  "result":  后面的内容用json.loads提取出来,然后通过replace将  "  替换成  \"  然后在拼接提交
Light紫星 发表于 2019-10-12 20:36
data.replace('"','\\"')
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-27 00:34

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表