I'm a student studying blockchain and bitcoin. I got raw block data of bitcoin block through web api as below.
resp = requests.get(url=url)
data = resp.text
If you change the ?format to json at the end of url, you can get json information, but
I would like to receive hex data as above and change hex data to json format through python code.
Is there a code I can change?
Please answer me. Thank you.
python blockchain hex json programming
The contents received in format=hex seem to have passed a binary to a hexastring. Generally, you can change a hex string to a binary
from binascii
b = binascii.unhexlify('313233')
in the same way possible.
However, it seems that the string taken from the url as an example in the question is not a string that can be easily replaced by json, but there is another special internal structure. If you don't know the structure, you can't change it to json.
If you really need json, it seems right to just get json's response and write it.
© 2024 OneMinuteCode. All rights reserved.