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')',因爲它利用字符串的字節數組。 –