如何使用python请求正确发送图像

时间:2019-05-28 13:14:27

标签: python python-requests binaryfiles

我将图像发送到了仿真浏览器中的服务器,但是没有成功。我捕获了formdata,但是我不了解某些字段。 file:(binary)是什么意思?我不知道如何正确发送此请求。

request headers:
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryILx3KlkmPpcwhIA9

form data:
name: jw7kyhmv.jpg     # this isn't my image name
scene: aePhotobankImageNsRule
file: (binary)

this is form data view source on chrome:

------WebKitFormBoundaryILx3KlkmPpcwhIA9
Content-Disposition: form-data; name="name"

jw7kyhmv.jpg
------WebKitFormBoundaryILx3KlkmPpcwhIA9
Content-Disposition: form-data; name="scene"

aePhotobankImageNsRule
------WebKitFormBoundaryILx3KlkmPpcwhIA9
Content-Disposition: form-data; name="file"; filename="Product-1.jpg" #this is my image name 
Content-Type: image/jpeg


------WebKitFormBoundaryILx3KlkmPpcwhIA9--
url = 'www.***.com'
files = {
            'file': (file_name, open(new_photo_path, 'rb'), 'image/jpeg')
        }
data = {
            'file': '(binary)',
            'name': 'jw7kyhmt.jpg',
            'cene': 'aePhotobankImageNsRule',
        }
headers['content-type'] = 'multipart/form-data; boundary=----WebKitFormBoundarylj2f9V2hGxUGirJq'
response = requests.post(url, headers=headers, data=data, files=files)
# response = requests.post(url, headers=headers, data=data, files=files)

0 个答案:

没有答案