Quantcast
Channel: Active questions tagged utf-8 - Stack Overflow
Viewing all articles
Browse latest Browse all 1200

How to decode base64 string to utf-8

$
0
0

I am using the programSubscribe method in solana blockchain api. after receiving the information, I have to convert the base-64 string, but for some reason I always get an error.

Here is the response from api:

{"jsonrpc": "2.0","method": "programNotification","params": {"result": {"context": {"slot": 289759455      },"value": {"pubkey": "DjyaRfgXKCpUP2fqh5SGX2yk7jEpcXbJVJWjLj1DFzKu","account": {"lamports": 6124800,"data": ["BgAAAAAAAAD+AAAAAAAAAAcAAAAAAAAAAwAAAAAAAAAJAAAAAAAAAAkAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAADKmjsAAAAA9AEAAAAAAABAS0wAAAAAAADKmjsAAAAAgJaYAAAAAAABAAAAAAAAAADKmjsAAAAAAMqaOwAAAAAFAAAAAAAAABAnAAAAAAAAGQAAAAAAAAAQJwAAAAAAAAwAAAAAAAAAZAAAAAAAAAAZAAAAAAAAABAnAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA5GoFmAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJPt654sNzQbAAAAAAAAAADYQ9d0mgAAAAAAAAAAAAAAyraoTAAAAADQtZzHdwAAAAAAAAAAAAAAHfoyehJqdBUAAAAAAAAAAPc7URIZaREAOL2YtIrv7Pwe8s39gEvtRHH0l+h6F76wS/F7nk99MLBB04riU/VWv9iV3EMmqrwjEgtppdns2Thw2DGc2pLXiT4FfmTXP1Zjc3V/Gxt77nQUXks10F9W4q2egtxQDbU9BpuIV/6rgYT7aH9jRhjANdrEOdwa6ztVmKDwAAAAAAFfS70UI/tcML4CU/hCEijxdtoxoROPKlt1WXDkfFTa93CTgXtA4ugNA+mm9JZ4J8Lt+HHTuVaHJ/djZISi5XFJuAh9+mIHapi0CmQtkPoSKDgrkZPQi/8nh5u2DUdmRRENB1GoKC2mEwX+KZw3uZjlhHHbETUDcxD4vhBFpgr27gQoDeSV8Ut5Alieq10Xc6JiU/o2gz5ulPDaQDFdlOdnAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAOW2K2XLO72m9WiI5m/ujmTcVWAZnA+IsR/ic70FnoqhyE2gH8nuAAAAAAAAAAAAAJ4CAAAAAAAAAAAAAAAAAAA=","base64"          ],"owner": "675kPX9MHTjS2zt1qfr1NYHuzeLXfQM9H24wFSUt1Mp8","executable": false,"rentEpoch": 18446744073709551615,"space": 752        }      }    },"subscription": 79356  }}

Here is a python code:

base64.b64decode(data['params']['result']['value']['account']['data'][0]).decode('utf-8')

Thats how raw bytes looks like:

b"\x06\x00\x00\x00\x00\x00\x00\x00\xfe\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00\t\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xca\x9a;\x00\x00\x00\x00\xf4\x01\x00\x00\x00\x00\x00\x00@KL\x00\x00\x00\x00\x00\x00\xca\x9a;\x00\x00\x00\x00\x80\x96\x98\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\xca\x9a;\x00\x00\x00\x00\x00\xca\x9a;\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x10'\x00\x00\x00\x00\x00\x00\x19\x00\x00\x00\x00\x00\x00\x00\x10'\x00\x00\x00\x00\x00\x00\x0c\x00\x00\x00\x00\x00\x00\x00d\x00\x00\x00\x00\x00\x00\x00\x19\x00\x00\x00\x00\x00\x00\x00\x10'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x009\x1a\x81f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x93\xed\xeb\x9e,74\x1b\x00\x00\x00\x00\x00\x00\x00\x00\xd8C\xd7t\x9a\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xca\xb6\xa8L\x00\x00\x00\x00\xd0\xb5\x9c\xc7w\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1d\xfa2z\x12jt\x15\x00\x00\x00\x00\x00\x00\x00\x00\xf7;Q\x12\x19i\x11\x008\xbd\x98\xb4\x8a\xef\xec\xfc\x1e\xf2\xcd\xfd\x80K\xedDq\xf4\x97\xe8z\x17\xbe\xb0K\xf1{\x9eO}0\xb0A\xd3\x8a\xe2S\xf5V\xbf\xd8\x95\xdcC&\xaa\xbc#\x12\x0bi\xa5\xd9\xec\xd98p\xd81\x9c\xda\x92\xd7\x89>\x05~d\xd7?Vcsu\x7f\x1b\x1b{\xeet\x14^K5\xd0_V\xe2\xad\x9e\x82\xdcP\r\xb5=\x06\x9b\x88W\xfe\xab\x81\x84\xfbh\x7fcF\x18\xc05\xda\xc49\xdc\x1a\xeb;U\x98\xa0\xf0\x00\x00\x00\x00\x01_K\xbd\x14#\xfb\\0\xbe\x02S\xf8B\x12(\xf1v\xda1\xa1\x13\x8f*[uYp\xe4|T\xda\xf7p\x93\x81{@\xe2\xe8\r\x03\xe9\xa6\xf4\x96x'\xc2\xed\xf8q\xd3\xb9V\x87'\xf7cd\x84\xa2\xe5qI\xb8\x08}\xfab\x07j\x98\xb4\nd-\x90\xfa\x12(8+\x91\x93\xd0\x8b\xff'\x87\x9b\xb6\rGfE\x11\r\x07Q\xa8(-\xa6\x13\x05\xfe)\x9c7\xb9\x98\xe5\x84q\xdb\x115\x03s\x10\xf8\xbe\x10E\xa6\n\xf6\xee\x04(\r\xe4\x95\xf1Ky\x02X\x9e\xab]\x17s\xa2bS\xfa6\x83>n\x94\xf0\xda@1]\x94\xe7g\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe5\xb6+e\xcb;\xbd\xa6\xf5h\x88\xe6o\xee\x8ed\xdcU`\x19\x9c\x0f\x88\xb1\x1f\xe2s\xbd\x05\x9e\x8a\xa1\xc8M\xa0\x1f\xc9\xee\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x9e\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"

And the error:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfe in position 8: invalid start byte

I have try to parse the information from api like jsonParsed. But its also sending me a base64 string. Also parsing with base58 not working because the string is to long.

i don't know how to convert it to utf-8. Pls. Help me


Viewing all articles
Browse latest Browse all 1200

Trending Articles