cmp*_*ezg 2 python file decoding
我正在编写一个从设备接收 Base 64 字符串的程序。该字符串是一个编码的 json 文件,我想这样解释它。
\n\n如果我这样做(使用 python base64 库):
\n\ndecoded = base64.decodestring(base64str) \nprint(decoded) \n
Run Code Online (Sandbox Code Playgroud)\n\n然后它打印出一堆乱码,因为原始数据不是字符串,而是文件。
\n\n我可以看到乱码之间的文件名,所以我想我正确接收了数据,但需要将其直接解释为文件而不是字符串。
\n\n我环顾四周并没有成功。尝试将字符串保存到文件中显然只会将所有乱码保存到文件中
\n\n我将非常感谢您帮助如何做到这一点!
\n\n64 进制字符串:
\n\nUEsDBBQACAAIAAAAIQAAAAAAAAAAAEEfAAALACAAbzNkM3h4Lmpzb25VVA0ABwAAAAAAAAAAAAAAAHV4CwABBAAAAAAEAAAAAO1ZbW/iOBD+vr8C5ev1UBIKtNwnlpc2UnlZoHvb3a6QSQxYm8RZxymwK/77zTiBJkB4OfWk+1CkqrbzPDOT8Xg8dn5/KMBPqweBy2wiGfdDrVb4pkbx93vbUrgmDW3BAsQBTNOuso8tj8yoaHB/ymaRIAnsWwa0L3VLr0eSt5YBDyNBO2T5wP3ZcM6FbBNbcgGSyvrVGUzm7zPNM4gDOqWC+jbtc+bLL8C6ubmY9gS0SuUS2qBnoS9/P2vQCp+12jdoMgca+tWzNhM8CpK2XAUUmgCktnzWYGTBHDmHIaOEz+eUzeYSuzp2iT9zaUK1qS+pGC+hCy+17a+gX6msv6+1SywegR1gct5kNObE96l7DOGyIGD+7COXknsANErGCWgjmnDmJI76AnMMlhf+LBWvdfPGLNE/SjdXBXxA8BULu+NPeYSnHMLXPMLXA4Rc722Mf6BTeYY7Bjh96I1q+QRyxINj8rgvmR/xKExPHxCmxA1pDqnlk4lL6x4kAhk5tMGFgCiLV7AU0XFam4SyLejPCMJjdZaiNnMhALfqVOY4S5PiNVkoCUTi2TRcMWyapLg9rafNzfB3tR+lJ94fMY+qDKbnzVoa+QAaMNYNs/wXUvICLM0ZoG1Aus5T0BZEo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d2o28iboL0nqlZkkvJcGhNekLs3HiX++ItLot2QtNH7sy4XJCZBoylERGeODT6s304/zvM4lBm2g0amb6YUvOqfCpbDPqOh+VZOPI45YPKxCOzCEC9TQQl5p6tTbzWTinTof599x1kpskIwNe4rILmd2A5DcZcPXJ5Sjg6RTg61HASBA/PK5EQY6rUZBdRVavSSdQqdnx1VT2PhqeggjwYGrqhwsm7fmeFHU/lUxSegasft1xBDg8/ri2y8PUiS6GfcALtt9pdlCb43+XLgoh9UMu0iHQC/D+DcxP8lia2e/i+2H8bGSkmX0Shgsoe1V4Q57EK4OdK/Et5p6E8z0+HgoEl9zm7mcqwjh4SzsI2Pv7XOCteFnXM3E0JC8UygLJhVoXYU/5eevgnbkYUoEvMqCB+j7IXAoRPZ2qBWeU84Bofz4wRJvR/1CGoOlp63D3QM9GgrYFhzoKAWa1UqweAZknQFbnSwU9YRbL5u3t7U21elvKQbpuhMjrYvUWf2apqqc+T2qPQbI09aJplPRy8qsoRLJHaW0mvAURceYoVgBpXG8SXZdKmNgf2UzXqTeSeEWKrtd0s6YbtWu9Vq7WStfp2U/4w4CqwMlMLMwms63+y3VKmHFrFo3KTVEvVm61g+A7iMEFWWXBpm4cRg+jCZjQISG+gmaWy8XNX/qrC94/N+8bfS197bz+sP7wD1BLBwiTXw4cIAcAAEEfAABQSwECFAMUAAgACAAAACEAk18OHCAHAABBHwAACwANAAAAAAAAAAAApIEAAAAAbzNkM3h4Lmpzb25VVAUABwAAAAB1eAAAUEsFBgAAAAABAAEARgAAAHkHAAAAAA==\n
Run Code Online (Sandbox Code Playgroud)\n\n“解码”的字符串:
\n\n!A ux o3d3xx.jsonUT \xef\xbf\xbdYmo\xef\xbf\xbd8\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbdP \xef\xbf\xbd\xef\xbf\xbd\'\xef\xbf\xbd\xef\xbf\xbd6RyY\xef\xbf\xbd{\xef\xbf\xbd\xdd\xae\xef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f\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd_\xef\xbf\xbd\xef\xbf\xbd\n \xef\xbf\xbd?7\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbdP\xef\xbf\xbd_ A!\xef\xbf\xbd_ A \xef\xbf\xbd\xef\xbf\xbdo3d3xx.jsonUTuxPKFy\n
Run Code Online (Sandbox Code Playgroud)\n\n希望有一种方法可以提取并保存文件而无需转换字符串。
\n当我这样做时,print(decoded[:20])
我实际上看到了这个:
b'PK\x03\x04\x14\x00\x08\x00\x08\x00\x00\x00!\x00\x00\x00\x00\x00\x00\x00'
Run Code Online (Sandbox Code Playgroud)
这是zip 文件PK\x03\x04
的“神奇数字” 。所以就这样对待它。将其保存到名为“mydata.zip”的文件中,然后像解压任何 zip 文件一样解压它,或者在 Python 中处理它,如下所示:
...
decoded = base64.decodestring(base64str)
import io, zipfile, json, pprint
with zipfile.ZipFile(io.BytesIO(decoded)) as zf:
for name in zf.namelist():
print(name)
with zf.open(name) as f:
data = json.loads(f.read().decode())
pprint.pprint(data)
Run Code Online (Sandbox Code Playgroud)
对于您的数据,首先打印文件名“o3d3xx.json”,然后打印数据:
{'Applications': [{'Description': '',
'ImagerConfiguration': [{'AutoExposureMaxLongShortFactor': 50,
'AutoExposureMinLongShortFactor': 2,
(... lots and lots and lots of data ...)
'StaticIPv4SubNetMask': '255.255.255.0',
'UseDHCP': False}}
Run Code Online (Sandbox Code Playgroud)