Flask测试无法在同一请求中上传文件和数据
Can't upload file and data in same request in Flask test
嗨,我正在尝试测试需要一个文件和一些值的端点,当我只上传文件时没有问题,但是当我添加它抛出的值时:
TypeError: 'str' does not support the buffer interface
我的代码是这样的:
headers = {'content-Type': 'multipart/form-data'}
response = self.client.post(base_url, headers=headers, data=dict(
some_value='test', some_other_value=False, image=(BytesIO(self.test_image), 'image.png'))
如果我这样做它会起作用:
headers = {'content-Type': 'multipart/form-data'}
response = self.client.post(base_url, headers=headers, data=dict(
image=(BytesIO(self.test_image), 'image.png'))
不知道这有什么关系,但是,当我将值从 False 更改为 'false' 时,它起作用了。
嗨,我正在尝试测试需要一个文件和一些值的端点,当我只上传文件时没有问题,但是当我添加它抛出的值时:
TypeError: 'str' does not support the buffer interface
我的代码是这样的:
headers = {'content-Type': 'multipart/form-data'}
response = self.client.post(base_url, headers=headers, data=dict(
some_value='test', some_other_value=False, image=(BytesIO(self.test_image), 'image.png'))
如果我这样做它会起作用:
headers = {'content-Type': 'multipart/form-data'}
response = self.client.post(base_url, headers=headers, data=dict(
image=(BytesIO(self.test_image), 'image.png'))
不知道这有什么关系,但是,当我将值从 False 更改为 'false' 时,它起作用了。