Python请求模块:等效的cURL --data命令

时间:2017-06-13 05:37:16

标签: python python-requests urllib urlencode

我正在尝试编写一个模仿我更改目标网页上数据的cURL命令的脚本:

curl -u username:password "https://website.com/update/"  --data "simChangesList=%5B%7B%22simId%22%3A760590802%2C%22changeType%22%3A2%2C%22targetValue%22%3A%220003077%22%2C%22effectiveDate%22%3Anull%7D%5D" --compressed

如上所示,我正在将一个url编码的字符串发布到目标网页。

以下代码不起作用:

import requests
import urllib

enc = urllib.quote('[{"simId":760590802,"changeType":2,"targetValue":000307,"effectiveDate":null}]')
simChangesList = 'simChangesList=' + enc
print simChangesList
auth = s.post(url, data=simChangesList)
print auth.text

即使我相当肯定上面的代码先前模仿了我的cURL命令,但显然不是。

我收到Required List parameter 'simChangesList' is not present错误。

使用Python中的requests模块POST一个url编码的字符串的cURL命令的等价物是什么?

编辑:

我尝试用simChangesList作为关键词制作多个词典,但我似乎无法做到。

以下是我的尝试:

simChangesList: [{"simId":760590802,"changeType":2,"targetValue":000307,"effectiveDate":null}]

data = {'simChangesList': ['simId': 760590802, 'changeType': 2, 'targetValue': '0003077', 'effectiveDate': null]}
data['simChangesList'] = ['simId': 760590802, 'changeType': 2, 'targetValue': '0003077', 'effectiveDate': null]
simChangesList:[{"simId":760590802,"changeType":2,"targetValue":"000307","effectiveDate":null}]

payload = {
'simChangesList':
[{'simId': '760590802',
'changeType': '2',
'targetValue': '0003077',
'effectiveDate': 'null'}]
}

0 个答案:

没有答案