Python binascii error odd length string



TypeError: Odd-length string #27

Comments

I am running Fedora 30.
I tried to update the list, but it just gives me «TypeError: Odd-length string».
Full traceback is here:
Traceback (most recent call last):
File «psi_client.py», line 440, in
update()
File «psi_client.py», line 311, in update
js = i[loc:].decode(‘hex’)
File «/usr/lib64/python2.7/encodings/hex_codec.py», line 42, in hex_decode
output = binascii.a2b_hex(input)
TypeError: Odd-length string

Any fix, or having a same issue?

The text was updated successfully, but these errors were encountered:

same here, i’m fedora 30 and run the docker:latest. during update got same error:
root@fefbd46bc6a8:

/psiphon# psiphon -u 100% [. ] 1409925 / 1409925Traceback (most recent call last): File «psi_client.py», line 440, in update() File «psi_client.py», line 311, in update js = i[loc:].decode(‘hex’) File «/usr/lib/python2.7/encodings/hex_codec.py», line 42, in hex_decode output = binascii.a2b_hex(input) TypeError: Odd-length string root@fefbd46bc6a8:

it seems «servers.dat» file did not generate in the normal way so serverlist did not get updated and timeout issue occurs, i used windows based server_list.dat and had no luck (format is different) i’m going to use android version and check whether that file is ok with linux or not!

Edit:
it seems this part of code has issue :

so i’ve edited this part with this code and the output file is structural the same with the original file but cannot be read (i’m so noob in python)

Источник

binascii.Error: Odd-length string #4

Comments

I think that no padding necessary isn’t always the case. An example is when trying to run examples/spend_p2sh_csv_p2pkh.py with:

By adding .zfill(64) to keys.py#L315, it seems to work fine. Please let me know if you need more information or if I’m doing something wrong.

The text was updated successfully, but these errors were encountered:

Thank you for reporting.

You get the error when you send the transaction to a node?

What error do you get exactly? The error that you mention comes up frequently when using a txid and/or vout that do not correspond to a valid UTXO.

Ideally a UTXO in testnet so that I can replicate the error would be great!

The error occurs when trying to use the script above, to just create the raw signed transaction. Should it matter if it’s from a valid UTXO? (even though in my local regtest it is)
The full error when running the above is:

I assumed the error was when you were sending it to a node. which is not uncommon given an invalid UTXO.

You are correct, if it happens during creation of the raw tx, the UTXO itself is irrelevant as long as the txid is proper hex (which it is). The padding does not matter while one works with numbers (e.g. line above) but it should matter with hex strings . not sure how the comment ended up there!

The hex need to be even so you are right. Good catch!

I will change and test tomorrow (run the existing tests, etc.).

Great stuff. It fixes it as expected! Maybe you would like to make a pull request? (otherwise, I will commit the change tomorrow)

Footer

© 2023 GitHub, Inc.

You can’t perform that action at this time.

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.

Источник

AnsibleVaultFormatError does not point to the source of the error #72276

Comments

SUMMARY

When an invalid hex string is provided as encrypted secret, the following error is returned to the user :

This error is not directly actionable, since it does not point to the source of the error. Ideally, the error would contain the filename and the line where the error was found, and the value that failed to be decoded.

ISSUE TYPE
COMPONENT NAME
ANSIBLE VERSION
STEPS TO REPRODUCE

Create a playbook that contains, for instance:

EXPECTED RESULTS
ACTUAL RESULTS

The text was updated successfully, but these errors were encountered:

Читайте также:  Что такое varnish error

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

You are correct in this not being actionable. I’m not sure how we could ever make it actionable.

We take the vault data, we remove newlines (which is required, the newlines are just there to keep YAML lines short), and then feed it to binascii.unhexlify . The error we get is simply binascii.Error(‘Odd-length string’) .

This indicates that the vault data is invalid, but due to the fact that it is odd-length.

We don’t know any more about this error, or where the source of the error is. Someone could have inserted some errant character into the middle of a vault data at any point. This is not a recoverable error.

The only recommended way to recover from this is to recreate the vault.

I’m unsure if we could indicate the source of where that vault string shows up.

It looks like all the functions that raise an AnsibleVaultFormatError take some encrypted text as input. Just including this text in the error would already make it much easier to find where the error comes from (the user would just rg the_invalid_string ). Adding a file name to the error should just be a matter to catch the error higher up, add the file name, and rethrow.

Источник

binascii — Convert between binary and ASCII¶

The binascii module contains a number of methods to convert between binary and various ASCII-encoded binary representations. Normally, you will not use these functions directly but use wrapper modules like uu or base64 instead. The binascii module contains low-level functions written in C for greater speed that are used by the higher-level modules.

a2b_* functions accept Unicode strings containing only ASCII characters. Other functions only accept bytes-like objects (such as bytes , bytearray and other objects that support the buffer protocol).

Changed in version 3.3: ASCII-only unicode strings are now accepted by the a2b_* functions.

The binascii module defines the following functions:

binascii. a2b_uu ( string ) В¶

Convert a single line of uuencoded data back to binary and return the binary data. Lines normally contain 45 (binary) bytes, except for the last line. Line data may be followed by whitespace.

binascii. b2a_uu ( data , * , backtick = False ) В¶

Convert binary data to a line of ASCII characters, the return value is the converted line, including a newline char. The length of data should be at most 45. If backtick is true, zeros are represented by ‘`’ instead of spaces.

Changed in version 3.7: Added the backtick parameter.

Convert a block of base64 data back to binary and return the binary data. More than one line may be passed at a time.

If strict_mode is true, only valid base64 data will be converted. Invalid base64 data will raise binascii.Error .

Contains only characters from the base64 alphabet.

Contains no excess data after padding (including excess padding, newlines, etc.).

Does not start with a padding.

Changed in version 3.11: Added the strict_mode parameter.

Convert binary data to a line of ASCII characters in base64 coding. The return value is the converted line, including a newline char if newline is true. The output of this function conforms to RFC 3548.

Changed in version 3.6: Added the newline parameter.

Convert a block of quoted-printable data back to binary and return the binary data. More than one line may be passed at a time. If the optional argument header is present and true, underscores will be decoded as spaces.

binascii. b2a_qp ( data , quotetabs = False , istext = True , header = False ) В¶

Convert binary data to a line(s) of ASCII characters in quoted-printable encoding. The return value is the converted line(s). If the optional argument quotetabs is present and true, all tabs and spaces will be encoded. If the optional argument istext is present and true, newlines are not encoded but trailing whitespace will be encoded. If the optional argument header is present and true, spaces will be encoded as underscores per RFC 1522. If the optional argument header is present and false, newline characters will be encoded as well; otherwise linefeed conversion might corrupt the binary data stream.

Читайте также:  Root genius network error

binascii. crc_hqx ( data , value ) В¶

Compute a 16-bit CRC value of data, starting with value as the initial CRC, and return the result. This uses the CRC-CCITT polynomial x 16 + x 12 + x 5 + 1, often represented as 0x1021. This CRC is used in the binhex4 format.

binascii. crc32 ( data [ , value ] ) В¶

Compute CRC-32, the unsigned 32-bit checksum of data, starting with an initial CRC of value. The default initial CRC is zero. The algorithm is consistent with the ZIP file checksum. Since the algorithm is designed for use as a checksum algorithm, it is not suitable for use as a general hash algorithm. Use as follows:

Changed in version 3.0: The result is always unsigned.

Return the hexadecimal representation of the binary data. Every byte of data is converted into the corresponding 2-digit hex representation. The returned bytes object is therefore twice as long as the length of data.

Similar functionality (but returning a text string) is also conveniently accessible using the bytes.hex() method.

If sep is specified, it must be a single character str or bytes object. It will be inserted in the output after every bytes_per_sep input bytes. Separator placement is counted from the right end of the output by default, if you wish to count from the left, supply a negative bytes_per_sep value.

Changed in version 3.8: The sep and bytes_per_sep parameters were added.

Return the binary data represented by the hexadecimal string hexstr. This function is the inverse of b2a_hex() . hexstr must contain an even number of hexadecimal digits (which can be upper or lower case), otherwise an Error exception is raised.

Similar functionality (accepting only text string arguments, but more liberal towards whitespace) is also accessible using the bytes.fromhex() class method.

exception binascii. Error В¶

Exception raised on errors. These are usually programming errors.

exception binascii. Incomplete В¶

Exception raised on incomplete data. These are usually not programming errors, but may be handled by reading a little more data and trying again.

Support for RFC compliant base64-style encoding in base 16, 32, 64, and 85.

Support for UU encoding used on Unix.

Support for quoted-printable encoding used in MIME email messages.

Источник

19.8. binascii — Convert between binary and ASCII¶

The binascii module contains a number of methods to convert between binary and various ASCII-encoded binary representations. Normally, you will not use these functions directly but use wrapper modules like uu , base64 , or binhex instead. The binascii module contains low-level functions written in C for greater speed that are used by the higher-level modules.

a2b_* functions accept Unicode strings containing only ASCII characters. Other functions only accept bytes-like objects (such as bytes , bytearray and other objects that support the buffer protocol).

Changed in version 3.3: ASCII-only unicode strings are now accepted by the a2b_* functions.

The binascii module defines the following functions:

binascii. a2b_uu ( string ) В¶

Convert a single line of uuencoded data back to binary and return the binary data. Lines normally contain 45 (binary) bytes, except for the last line. Line data may be followed by whitespace.

binascii. b2a_uu ( data ) В¶

Convert binary data to a line of ASCII characters, the return value is the converted line, including a newline char. The length of data should be at most 45.

binascii. a2b_base64 ( string ) В¶

Convert a block of base64 data back to binary and return the binary data. More than one line may be passed at a time.

binascii. b2a_base64 ( data ) В¶

Convert binary data to a line of ASCII characters in base64 coding. The return value is the converted line, including a newline char. The newline is added because the original use case for this function was to feed it a series of 57 byte input lines to get output lines that conform to the MIME-base64 standard. Otherwise the output conforms to RFC 3548.

Читайте также:  Doom steam fatal error

binascii. a2b_qp ( data, header=False ) В¶

Convert a block of quoted-printable data back to binary and return the binary data. More than one line may be passed at a time. If the optional argument header is present and true, underscores will be decoded as spaces.

binascii. b2a_qp ( data, quotetabs=False, istext=True, header=False ) В¶

Convert binary data to a line(s) of ASCII characters in quoted-printable encoding. The return value is the converted line(s). If the optional argument quotetabs is present and true, all tabs and spaces will be encoded. If the optional argument istext is present and true, newlines are not encoded but trailing whitespace will be encoded. If the optional argument header is present and true, spaces will be encoded as underscores per RFC1522. If the optional argument header is present and false, newline characters will be encoded as well; otherwise linefeed conversion might corrupt the binary data stream.

binascii. a2b_hqx ( string ) В¶

Convert binhex4 formatted ASCII data to binary, without doing RLE-decompression. The string should contain a complete number of binary bytes, or (in case of the last portion of the binhex4 data) have the remaining bits zero.

binascii. rledecode_hqx ( data ) В¶

Perform RLE-decompression on the data, as per the binhex4 standard. The algorithm uses 0x90 after a byte as a repeat indicator, followed by a count. A count of 0 specifies a byte value of 0x90 . The routine returns the decompressed data, unless data input data ends in an orphaned repeat indicator, in which case the Incomplete exception is raised.

Changed in version 3.2: Accept only bytestring or bytearray objects as input.

Perform binhex4 style RLE-compression on data and return the result.

binascii. b2a_hqx ( data ) В¶

Perform hexbin4 binary-to-ASCII translation and return the resulting string. The argument should already be RLE-coded, and have a length divisible by 3 (except possibly the last fragment).

binascii. crc_hqx ( data, value ) В¶

Compute a 16-bit CRC value of data, starting with value as the initial CRC, and return the result. This uses the CRC-CCITT polynomial x 16 + x 12 + x 5 + 1, often represented as 0x1021. This CRC is used in the binhex4 format.

binascii. crc32 ( data [ , value ] ) В¶

Compute CRC-32, the 32-bit checksum of data, starting with an initial CRC of value. The default initial CRC is zero. The algorithm is consistent with the ZIP file checksum. Since the algorithm is designed for use as a checksum algorithm, it is not suitable for use as a general hash algorithm. Use as follows:

Changed in version 3.0: The result is always unsigned. To generate the same numeric value across all Python versions and platforms, use crc32(data) & 0xffffffff .

Return the hexadecimal representation of the binary data. Every byte of data is converted into the corresponding 2-digit hex representation. The returned bytes object is therefore twice as long as the length of data.

binascii. a2b_hex ( hexstr ) В¶ binascii. unhexlify ( hexstr ) В¶

Return the binary data represented by the hexadecimal string hexstr. This function is the inverse of b2a_hex() . hexstr must contain an even number of hexadecimal digits (which can be upper or lower case), otherwise an Error exception is raised.

exception binascii. Error В¶

Exception raised on errors. These are usually programming errors.

exception binascii. Incomplete В¶

Exception raised on incomplete data. These are usually not programming errors, but may be handled by reading a little more data and trying again.

Module base64 Support for RFC compliant base64-style encoding in base 16, 32, 64, and 85. Module binhex Support for the binhex format used on the Macintosh. Module uu Support for UU encoding used on Unix. Module quopri Support for quoted-printable encoding used in MIME email messages.

Источник

Оцените статью
toolgir.ru
Adblock
detector