首页 > 解决方案 > 发送带有枕头图像的 POST 请求

问题描述

我从 pymongo 得到这样的图像:

    def get_my_photo(self, user_id):
        res = self.db.find_one({'user_id': user_id})
        image_data = BytesIO(res['photo'])
        image = Image.open(image_data)
        image_data = BytesIO()
        image.save(image_data, "JPEG")
        image_data.seek(0)
        return image_data

然后我尝试使用 image_data 发送 POST 请求:

request = requests.post(url, files={'photo': image})

但标题是: 'Content-Type': 'text/html; charset=windows-1251'. 并且没有照片上传。如何正确发送带有请求的 Pillow 图像?谢谢。

编辑:在这篇文章中找到解决方案

标签: pythonrequestpython-imaging-librarypymongo

解决方案


推荐阅读