首页 > 解决方案 > 如何解决“BufferedReader 类型的对象不是 JSON 可序列化的”?

问题描述

我正在向后端发送 POST 请求中的表单数据和图像:

data = {
        'username': self.ids['username'].text,
        'email': self.email_field.text,
        'password': self.ids['password'].text,
        'data': json.dumps({
            'first_photo': open(f'{self.selfies_path}/first.png', 'rb'),
            'second_photo': open(f'{self.selfies_path}/second.png', 'rb'),
            'third_photo': open(f'{self.selfies_path}/third.png', 'rb')
        })
      }
response = requests.post('http://5.10.203.170/auth/register', files=data)

以上抛出python : TypeError: Object of type BufferedReader is not JSON serializable

我怎样才能使它工作?

标签: pythonjsonpython-requests

解决方案


将字节转换为 base64 并在您的网站代码中解密


推荐阅读