我是一个请求/ python菜鸟。我发现GET请求没有问题,但是找不到如何用POST正确编码那些-F参数
http://docs.python-requests.org/en/master/user/quickstart/
我试图弄清楚如何使请求能够处理包含表单数据的POST请求?
curl -X POST "https://falcon-sandbox.com/api/v2/submit/file?_timestamp=1548810863364" -H "accept: application/json" -H "user-agent: Falcon Sandbox" -H "api-key:xxx" -H "Content-Type: multipart/form-data" -F "file=@test.pdf;type=application/pdf" -F "environment_id=160"
答案 0 :(得分:2)
import requests
session = requests.Session()
headers = {'accept' : 'application/json',
'user-agent': 'Falcon Sandbox',
'api-key':'xxx',
'Content-Type': 'multipart/form-data'}
data = {'enviroment_id' : '160'}
files = {"file": open('test.pdf', "rb")}
session.post("https://falcon-sandbox.com/api/v2/submit/file", headers = headers, data = data, files = files)
希望我什么都没错过,但是结构应该相同。