First find the encoding of the string and then decode it... to do this you will need to make a byte string by adding the letter 'b' to the front of the original string.

Try this:

import chardet

s = "Aur\xc3\xa9lien"
bs = b"Aur\xc3\xa9lien"

encoding = chardet.detect(bs)["encoding"]

str = s.encode(encoding).decode("utf-8")

print(str)

If you are reading the text from a file you can detect the encoding using the magic lib, see here: https://stackoverflow.com/a/16203777/1544937

Answer from jgphilpott on Stack Overflow
🌐
Tutorialspoint
tutorialspoint.com › python › string_decode.htm
Python String decode() Method
The python string decode() method decodes the string using the codec registered for its encoding. The encoded string can be decoded and the original string can be obtained with the help of this function.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-strings-decode-method
Python Strings decode() method - GeeksforGeeks
July 11, 2025 - The decode() method in Python is used to convert encoded text back into its original string format. It works as the opposite of encode() method, which converts a string into a specific encoding format.
🌐
Python
docs.python.org › 3 › library › codecs.html
codecs — Codec registry and base classes
February 23, 2026 - Each codec has to define four interfaces to make it usable as codec in Python: stateless encoder, stateless decoder, stream reader and stream writer. The stream reader and writers typically reuse the stateless encoder/decoder to implement the file protocols.
🌐
Mimo
mimo.org › glossary › python › string-decode
Python string decode(): Syntax, Usage, and Examples
Use decode() in Python to convert bytes to readable strings using the correct encoding. It's essential for processing files, APIs, or web content.
🌐
Python documentation
docs.python.org › 3 › howto › unicode.html
Unicode HOWTO — Python 3.14.5rc1 documentation
February 23, 2026 - Unicode data is usually converted to a particular encoding before it gets written to disk or sent over a socket. It’s possible to do all the work yourself: open a file, read an 8-bit bytes object from it, and convert the bytes with bytes.decode(encoding).
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › str › decode.html
decode — Python Reference (The Right Way) 0.1 documentation
>>> 'źdźbło'.decode('windows-1250') # polish word meaning a blade of grass u'\u0139\u015fd\u0139\u015fb\u0139\u201ao' >>> 'źdźbło'.decode('ascii', 'strict') Traceback (most recent call last): File "<interactive input>", line 1, in <module> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 0: ordinal not in range(128) >>> 'źdźbło'.decode('ascii', 'ignore') u'dbo' >>> 'źdźbło'.decode('ascii', 'replace') u'\ufffd\ufffdd\ufffd\ufffdb\ufffd\ufffdo'
Find elsewhere
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-string-encode-decode
Python String Encode and Decode: Complete Guide | DigitalOcean
August 3, 2022 - Master Python string encode() and decode() methods. Learn UTF-8, ASCII, Unicode handling, error handling modes, and practical encoding/decoding examples.
🌐
URL Decode
urldecoder.org › dec › python
URL Decoding of "python" - Online
Decode python from URL-encoded format with various advanced options. Our site has an easy to use online tool to convert your data.
🌐
AskPython
askpython.com › home › python encode() and decode() functions
Python encode() and decode() Functions - AskPython
February 16, 2023 - Since encode() converts a string to bytes, decode() simply does the reverse.
🌐
Python Module of the Week
pymotw.com › 2 › codecs
codecs – String encoding and decoding - Python Module of the Week
Until that point, calls to encode() or decode() will not return any data. When the last bit of data is passed in, the argument final should be set to True so the codec knows to flush any remaining buffered data. $ python codecs_incremental_bz2.py Text length : 27 Repetitions : 50 Expected len: 1350 Encoding:................................................. Encoded : 99 bytes Total encoded length: 99 Decoding:............................................................ ............................
Top answer
1 of 3
74

Neither is better than the other, they do exactly the same thing. However, using .encode() and .decode() is the more common way to do it. It is also compatible with Python 2.

2 of 3
19

To add to Lennart Regebro's answer There is even the third way that can be used:

encoded3 = str.encode(original, 'utf-8')
print(encoded3)

Anyway, it is actually exactly the same as the first approach. It may also look that the second way is a syntactic sugar for the third approach.


A programming language is a means to express abstract ideas formally, to be executed by the machine. A programming language is considered good if it contains constructs that one needs. Python is a hybrid language -- i.e. more natural and more versatile than pure OO or pure procedural languages. Sometimes functions are more appropriate than the object methods, sometimes the reverse is true. It depends on mental picture of the solved problem.

Anyway, the feature mentioned in the question is probably a by-product of the language implementation/design. In my opinion, this is a nice example that show the alternative thinking about technically the same thing.

In other words, calling an object method means thinking in terms "let the object gives me the wanted result". Calling a function as the alternative means "let the outer code processes the passed argument and extracts the wanted value".

The first approach emphasizes the ability of the object to do the task on its own, the second approach emphasizes the ability of an separate algoritm to extract the data. Sometimes, the separate code may be that much special that it is not wise to add it as a general method to the class of the object.

🌐
Medium
medium.com › @vivekmcm1 › understanding-pythons-encode-and-decode-with-real-world-examples-5d2080d66f01
Understanding Python’s encode() and decode() with Real-World Examples | by Vivek | Medium
August 30, 2025 - ... text = "Hello World" byte_text ... because ASCII cannot represent it. ... Decoding is the reverse process: converting bytes back into a string....
🌐
The New Stack
thenewstack.io › home › decode any python code with this 5-step method
Decode Any Python Code With This 5-Step Method - The New Stack
July 7, 2025 - In this tutorial, we’ll walk through a small application with unclear naming. Using a checklist as our guide, we’ll take it step by step to decode what’s going on.
🌐
Scaler
scaler.com › home › topics › python decode() function
Python Decode() Function - Scaler Topics
April 9, 2024 - The python decode method is used to decode the encoded form of a string. The python decode uses the codecs that are registered for encoding. By default, the python decode uses the UTF-8 encoding value.
🌐
Real Python
realpython.com › python-encodings-guide
Unicode & Character Encodings in Python: A Painless Guide – Real Python
May 29, 2024 - The complete list of accepted encodings is buried way down in the documentation for the codecs module, which is part of Python’s Standard Library. There’s one more useful recognized encoding to be aware of, which is "unicode-escape". If you have a decoded str and want to quickly get a representation of its escaped Unicode literal, then you can specify this encoding in .encode():
🌐
Finxter
blog.finxter.com › python-decode
Python decode() – Be on the Right Side of Change
The decode() method converts/decodes from one encoding scheme for the argument string to the desired encoding scheme. It is the opposite of the Python encode() method.
🌐
Reddit
reddit.com › r/learnpython › decode and encode with python
r/learnpython on Reddit: Decode and Encode with Python
July 28, 2022 -

I am getting a byte base64 encoded data and I have to decode it but it is showing an error on the last line.

Error - UnicodeDecodeError: 'ascii' codec can't decode byte 0x82 in position 1: ordinal not in range(128)

base64_bytes = base64_message.encode('ascii')
print(base64_bytes)
#decode
message_bytes = base64.b64decode(base64_bytes)
message = message_bytes.decode('ascii')
🌐
Educative
educative.io › answers › what-is-bytesdecode-in-python
What is bytes.decode() in Python?
bytes.decode() is used to decode bytes to a string object. Decoding to a string object depends on the specified arguments. It also allows us to mention an error handling scheme to use for seconding errors.
🌐
Medium
medium.com › @nonamedev › encoding-and-decoding-articles-using-python-211d5bdc3ac0
Encoding and Decoding Articles using Python
April 4, 2023 - We then decode the encoded article using the UTF-8 encoding. Finally, we open a new file called decoded_article.txt in write mode and write the decoded article to the file as a string. ... In this example, we have shown how to use Python to encode and decode articles using the UTF-8 encoding.