non-hexadecimal number found in fromhex() arg at position 7
时间: 2024-04-29 16:23:07 浏览: 547
This error occurs when the argument passed to the `fromhex()` method in Python contains a non-hexadecimal digit at a position other than a multiple of 2.
For example, consider the following code:
```
s = '68656c6c6f20776f726c64z'
b = bytes.fromhex(s)
```
In this code, the string `s` contains a non-hexadecimal digit `z` at position 17 (counting from 0). This causes the `fromhex()` method to raise a `ValueError` with the message "non-hexadecimal number found in fromhex() arg at position 17".
To fix this error, you need to ensure that the argument passed to `fromhex()` contains only hexadecimal digits. If you are reading the string from a file or user input, you may need to validate the input before passing it to `fromhex()`.
阅读全文