TransWikia.com

Python | проблема с FileIO

Stack Overflow на русском Asked by icYFTL on January 22, 2021

Есть файл в base64:

data = '''UEsDBBQAAAAIABeAJVEPqTEW1gAAAJ0BAAAJAAAATWFpbi5qYXZhjVCxagMxDN0D+QfhyYZifFmP
LrcV0qUZSwafo7omPvs46xqS0n+PnKYESgt5Mki23pMeHq3bW4/g8qAJC7XLRY1x7mNw4KItBZ5t
SPBZn4FxbRWyxOkjhx0MTJAbmkLyr1uwky+q8uGKzsYIfQOPkPBwucnGPIDoJnua91Zw+YI7Titt
VHvT9Y12OeaJhaKLM4r2x0PF5lgIB51n0iNvppgkCzzSU3rLUtVKihJOKJRq75Ctg3+nhKVI9cvE
AWuLXayM0eY+E/9M+5tP+fvzbtyv5YLPGVBLAwQUAAAACAAvgCVR+ICwdLMBAADTBAAACQAAAEJh
bGwuamF2YX1Sy07DMBC8V+o/rCIBKYpMQeJCKQe4gETFgQMXLibZpgbHjmKnCBD/jh95uUrwoXU8
49nZWZc0/aA5QioLolHp1Xw2n7GilJWGd7qnhFORk9NVeFhrxsk9VbsNLccgfzyflfUbZymknCoF
t5Rz+LHHYFYDMaFBsW9cBafPumIih0JmyEeRVHJZhUgmzT/CJ7J859sYgLZ23NZKAv0k0ExCnYU1
DM3SO6aIEUBYDz13kJODdWC7A506rAPnHeiLwbp3b6HfgyZMqtfeawJPb++Y6hvIUT+IrYyNUTg7
e9AnCio0zX4ZF5Udq9ijYCh0X3FMJmOpLS/wE5qxHlLixcC0pZOy1nFkc4iSPppxViFNIi3NfYzz
XDgtz32M83xMLbEZVTdzuyrUdSXclYk0m6lr6TdxMOrmuofIVlYFNWWfTYNXcJS9io3t4QqO1Ku4
szb99sUZMXtysY2SXq1dXUpTmH+QLXgAujymwD4DmO7VPJZHSxOoVLwYtMu2EA8f4g2ckyUcHwev
8xouyXLRXxrkFDnZaPWf4uWY4vlyUnKDGasL4K3hoXrLuUe6/4qGTZufP1BLAQIfABQAAAAIABeA
JVEPqTEW1gAAAJ0BAAAJACQAAAAAAAAAIAAAAAAAAABNYWluLmphdmEKACAAAAAAAAEAGAApkVWS
hIPWAUShGNp3j9YBFQlyuoSD1gFQSwECHwAUAAAACAAvgCVR+ICwdLMBAADTBAAACQAkAAAAAAAA
ACAAAAD9AAAAQmFsbC5qYXZhCgAgAAAAAAABABgASlIPrYSD1gFkwfbZd4/WAQducbqEg9YBUEsF
BgAAAAACAAIAtgAAANcCAAAAAA==
'''

Файл: test.zip

Пытаюсь преобразовать данный base64 в io.FileIO

import base64
import io
    
file = io.FileIO(base64.decodebytes(data.encode('UTF-8')), 'rb')

Ошибка:

file = io.FileIO(base64.decodebytes(data.encode('UTF-8')), 'rb')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 11: invalid start byte

При этом, при попытке открыть байты в io.BytesIO – все работает и я могу сохранить оригинальный файл.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP