I pass on the following test message. At the entrance to the program I get - . I do data.encode('utf-8') , to which I get an error:

 UnicodeDecodeError: 'ascii' codec can't decode byte 0xb5 in position 0: ordinal not in range(128) 

How to get your word test inside the program?

  • Without a full description, how exactly you transmit it will be difficult to answer, for - not like the test well, there’s no way at all - andreymal
  • one
    The error message hints that data is already a set of bytes (where did you get data from?), You do not need to use encode. Perhaps on the contrary decode should be called to get Unicode for text output. What does it mean to get at the entrance to the program? How exactly: via sys.argv, sys.stdin, from the network, from a file? Edit the question and print repr(data) with a description of where the data is taken from and where you want to transfer the data. - jfs

1 answer 1

'ascii' codec can't ...... - the interpreter says that the ascii encoding cannot DECODE

Look at what encoding is used when sending a message via SOAP. it is necessary for messages to use UTF-8 encoding (which is the default in PYTHON)

Not every byte contains a valid ASCII character and not every sequence of bytes is valid in a UTF-8 or UTF-16 encoding. If, while decoding a binary sequence, an unexpected byte is encountered, a UnicodeDecoreError exception will be thrown.

Exception can be avoided.

 data.decode('UTF-8', errors='replace')