【发布时间】:2021-03-23 06:10:36
【问题描述】:
我正在通过 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
我怎样才能让它工作?
【问题讨论】:
-
你为什么要把整个文件(从
open返回)分配给一个json键?考虑只发送文件的路径,前端应该能够提供它 -
this 回答你的问题了吗?
标签: python json python-requests