2
例如我送文件蟒蛇3.5 + aiohttp:类型错误:一类字节对象是必需的,而不是“海峡”在使用时io.BytesIO
with open('test_zip'), 'wb') as f:
f.write(content)
res = requests.post(URL, data={'file': content})
然后我试图让服务器端的文件
async def handle(request):
form = await request.post()
data = io.BytesIO((form['file']))
with open('test_zip_2', 'wb') as file:
file.write(data)
并发生错误,但我可以打开一个新的归档与Ubuntu
data = io.BytesIO((form['file'])) TypeError: a bytes-like object is required, not 'str'
我的猜测是'form ['file']'属于'str'类型。尝试传递'form ['file']。encode('ascii')',因为它利用字符串的字节数组。 –