Python: Post Request with image files

倾然丶 夕夏残阳落幕 提交于 2019-12-04 08:56:11

Add a this header:

request.add_header("Content-type", "application/x-www-form-urlencoded; charset=UTF-8")

Also, the image parameter you're sending is a string, not the contents of the image file. You need to b64 encode it

import base64

with open("image.jpg", "rb") as image_file:
    encoded_image = base64.b64encode(image_file.read())

then use encoded_image instead of '~/image.jpg' in raw_params

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!