python - 如何解决“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
我怎样才能使它工作?
解决方案
将字节转换为 base64 并在您的网站代码中解密
推荐阅读
- android - Android 模拟器 UI 坏了
- python - form.save() 之前的行没有保存正确的值
- android - 图形对象显示错误
- graphics - 为什么 VkShaderStageFlagBits 是位掩码?
- angular - 如何使用 Typescript 和 Angular 将 JSON 转换为复杂对象
- css - :first-child with *ngFor 无法正常工作
- html - flex order 属性在 Safari 中不起作用
- python-2.7 - 使用 pd.read_sql() 从 oracle 数据库中提取大数据(>500 万条记录),使得 sql 执行非常慢
- java - Android Studio 布局设计
- python - 在python中对(多?)线程使用相同的变量名