url = host + path
headers = {...}
data = {...}
files = {...}
files两种类型: 字典和 元组
{
"field1" : ("filename1", open("filePath1", "rb")),
"field2" : ("filename2", open("filePath2", "rb"), "image/jpeg"),
"field3" : ("filename3", open("filePath3", "rb"), "image/jpeg", {"refer" : "localhost"})
}
字段对应:{"字段名": ("filename","fileobject", "content-type", "headers")}
或者
{
"field1" : open("filePath1", "rb"),
"field2" : open("filePath2", "rb"),
"field3" : open("filePath3", "rb")
元组形式:
[
("field1" , ("filename1", open("filePath1", "rb"))),
("field2" , ("filename2", open("filePath2", "rb"), "image/jpeg")),
("field3" , ("filename3", open("filePath3", "rb"), "image/jpeg", {"refer" : "localhost"}))
]
字段对应:["字段名", ("filename","fileobject", "content-type", "headers")]
data = requests.post(url,files=files,data=data_dict,headers=headers)
print(data.content.decode("utf-8"))
注: 上述可能filename不支持中文名,可以 D:\Users\jiangbo.xu\AppData\Local\Programs\Python\Python35\Lib\site-packages\urllib3\fields.py 50行左右
value = '%s*=%s' % (name, value) 改成 value = '%s=%s' % (name, value)
原文地址:https://www.cnblogs.com/wanderingfish/p/10987332.html
时间: 2024-10-11 04:13:18