pandas Python ValueError:在位置 1 处的 fromhex() arg 中找到非十六进制数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51369750/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python ValueError: non-hexadecimal number found in fromhex() arg at position 1
提问by Bikiran Das
Trying to Decode the following Hex Code to Ascii
尝试将以下十六进制代码解码为 Ascii
j =['0x00003A01C01173D676B644D4E040DB9CC01173D676B62069311401000009416E64726F69644150010882848B962430486C32040C12186030140100000FAC040100000FAC040100000FAC020C002D1A2C0103FF00000000000000000000000000000000000000000000DD070050F2020001007F0400000A02']
J = [ '0x00003A01C01173D676B644D4E040DB9CC01173D676B62069311401000009416E64726F69644150010882848B962430486C32040C12186030140100000FAC040100000FAC040100000FAC020C002D1A2C0103FF00000000000000000000000000000000000000000000DD070050F2020001007F0400000A02']
hex_to_ascii = bytes.fromhex(j)
the following is throwing an error - ValueError: non-hexadecimal number found in fromhex() arg at position 1
以下是引发错误 - ValueError:在位置 1 处的 fromhex() arg 中找到的非十六进制数
if any one can help with issue.
如果有人可以帮助解决问题。
回答by Andrej Kesely
You need to remove first 0x
from the string:
您需要0x
先从字符串中删除:
j =['0x00003A01C01173D676B644D4E040DB9CC01173D676B62069311401000009416E64726F69644150010882848B962430486C32040C12186030140100000FAC040100000FAC040100000FAC020C002D1A2C0103FF00000000000000000000000000000000000000000000DD070050F2020001007F0400000A02']
hex_to_ascii = bytes.fromhex(j[0][2:])
print(hex_to_ascii)
This prints:
这打印:
b'\x00\x00:\x01\xc0\x11s\xd6v\xb6D\xd4\xe0@\xdb\x9c\xc0\x11s\xd6v\xb6 i1\x14\x01\x00\x00\tAndroidAP\x01\x08\x82\x84\x8b\x96##代码##Hl2\x04\x0c\x12\x18`0\x14\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x04\x01\x00\x00\x0f\xac\x02\x0c\x00-\x1a,\x01\x03\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xdd\x07\x00P\xf2\x02\x00\x01\x00\x7f\x04\x00\x00\n\x02'