gpt4 book ai didi

python - 将curl请求转换为python请求

转载 作者:太空宇宙 更新时间:2023-11-03 21:34:31 24 4
gpt4 key购买 nike

我正在尝试将 cURL 命令转换为 python 请求,但遇到了困难。也许有人会有想法。

我正在使用这个site供引用,我有这样一个 cURL 命令:

curl -F "file=@myfile.json" -H "Authorization: ApiKey xxxxxxxxxxx" -F 'scan_type=Arachni Scan' -F 'tags=test' -F 'active=true' -F 'scan_date=2018-11-15' -F 'engagement=/api/v1/engagements/1/'  -F 'eid=1' https://example.com:443/api/v1/importscan/

转换为 python 后,我的脚本摘录如下所示:

files = {
'file': ('myfile.json', open('myfile.json', 'rb')),
'scan_type': 'Arachni Scan',
'tags': 'test',
'active': 'true',
'scan_date': '2018-11-15',
'engagement': '/api/v1/engagements/1/',
'eid': '1',
}

response = requests.post('https://example.com:443/api/v1/importscan/', headers=headers, files=files)
print response.text

不幸的是,cURL命令成功了,但是python请求返回了

{"error": "Request is not valid JSON."}

我在这里缺少什么?谢谢!

最佳答案

import json

response = requests.post('https://example.com:443/api/v1/importscan/', headers=headers, files=json.dumps(files))

使用 json.dumps 就可以了。

关于python - 将curl请求转换为python请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53323202/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com