Hi there I'm using suds to download a large data file, the download returns as a bytes object which can then be saved as a zip folder of individual csv files.
If I simply print the returned bytes object I get something like this:
<class 'bytes'>
b'PK\x03\x04\x14\x00\x08\x08\x08\x00\xe5P?X\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\r\x00\x00\x00jobstatus.csvU\x90Oo\xc20\x0c\xc5\xef\x95\xfa\x1dr\xd9\xcd\xa2!E\x8ck\xf93\xb1i\x1d\x1d \xa4\xed\x82\xa2\xd4\x83\x88\xd0 \xc7\xdd\xd6o\xbfv\xb0\t\x0e>\xf8\xd9\xfa\xbdg\xc7\xd1\xd2\x86\x83\xc8}\x89\x0e6H\xc1\xfa\n&\xfeS\x93\xd5\x95A\x91k&\xfb-\xa6\x9a1\x8e\xf2l\xd2{\x86\x81\x94=)A\r\x13\xd9O\x94T\x838z\xd1G\x84\xc5W\x85\x04\x1b\xedl\x19Gs,w\xb8\xc4\x93\'\xb6\xd5\x0e\xb2\xf1\xbe\xd1\x0cLu\x8b\xf9\x97\xb7\x9d\xf7v\x8a\xc6\x1fO>X\xee\xbco6\xe3\xa8h7?\xbc\xb3\x1e\xb2J\xbb&\xd8\xf0\x9b\xe5bV\x907\x18\x02\x960\xf7\xael\x89\x97\xe9\xf8x\xe8J\xdc\xaa\xb9\xa6\x03\xb2h\x13\xd6\x08\x93\x9a\x08+\xd3@f\x0c\x9eX\xdc\xc1\xd4\x12\x1a\xf6\xd4\xc0C\xed\x9cX\x13\xa2(4\xefa\xd5\x8aX\x8a\xdf\x00lM\x10+\xd6\\\x07h\xef\x9e\xadf\xafkH\xe5\xdf+ +\x1e\xe1\r\xc3\xb5\xf44H\xd3\xeb~(\xe5h\xa4\xeeS\xd5S\n\xde\xb3%\xf4\xcf\x0f=\xc3\x92\x0e\x91\xcc\x17\xf9,\xb9\xd0\xe3\xe8\x07PK\x07\x08\xd9\xf9\xc9\x1c\x1c\x01\x00\x00\xa5\x01\x00\x00PK\x03\x04\x14\x00\x08\x08\x08\x00\xe5P?X\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00,\x00\x00\x00Positions-20240130-HedgeReporting-ABhyat.csv\xdd}ks#\xd7\x91\xe5wE\xe8? .....
My code to save this data to a zip file is as follows:
>
> #download the data
> attachment = client.service.GetExportJob(usr, cid, pwd, jobId)
> #path to save zip file
> zipPath = os.path.join(savePath, attachment.FileName)
>
> byteArray = base64.b64decode(attachment.BinaryData)
> print(type(byteArray))
> print(byteArray)
> with open(zipPath, 'wb') as f:
> f.write(byteArray)
> f.flush()
> f.close()
I've tried the suggestions here Converting a Bytes object into a Pandas dataframe and here How to convert bytes data but I still get the following error from pandas instead of each csv file in a separate dataframe (which is what I need)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa3 in position 1: invalid start byte