简体   繁体   中英

how do i convert odd length hexadecimal string to byte format in python 3.5 and above?

in python 3.7.2 i am trying to test bitcoin testnet code. i am trying to convert odd length testnet private key to byte format but no matter what i try i cannot do it there is always some error mainly because all the functions i tried cannot Handel odd length address. any suggestions guys? so far i have tried

import codecs 
odd_len_str = "93AZYqkwkPsKAjHg7FqjXVMukwRrXkzGXYFNUsov2zFhDdfH8DT" #length=51
decode_hex = codecs.getdecoder("hex_codec") 
decode_hex(odd_len_str)[0]

import binascii
binascii.hexlify(odd_len_str) #doesn't work

bytes.fromhex(odd_len_str) #doesn't work

error msg from the first method is:

_codec.py", line 19, in hex_decode
    return (binascii.a2b_hex(input), len(input))
binascii.Error: Odd-length string

What is odd_len_str ? You're not showing us what it is.

sorry folks. hear i was trying to convert bit coin address directly to bytes type assuming they are in hexadecimal form but they are not so first have to convert them to hexadecimal notation using base58 then convert them to bytes

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM