![](/img/trans.png)
[英]openpyxl - TypeError: a bytes-like object is required, not '_io.BytesIO'
[英]python 3.5 + aiohttp: TypeError: a bytes-like object is required, not 'str' when use 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打开一个新的存档
数据= io.BytesIO((form ['file']))TypeError:需要一个类似字节的对象,而不是'str'
你并不需要转换的FileField到io.BytesIO
可言。
使用FileField.file.read()
获取文件内容:
async def handle(request):
form = await request.post()
with open('test_zip_2', 'wb') as f:
f.write(form['file'].file.read())
请参阅文件上载 part-aio文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.