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
🌐
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.
🌐
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.
Discussions

python - How to decode a text in python3? - Stack Overflow
The problem is that the Python string has some characters as binary data, not interpreted as unicode code points (which it is an hidden/not very well know feature of Python [and most programmers should never see it]). 2021-02-05T10:38:21.543Z+00:00 ... You have UTF-8 decoded as latin-1, so ... More on stackoverflow.com
🌐 stackoverflow.com
Decode and Encode with Python
You don't need to encode a base64 message, it's already ascii by definition. But the result you get from decoding matches the original message, and so isn't necessarily ascii. Assuming you originally encoded it into utf-8, you'd need to decode it back from utf-8 not ascii. More on reddit.com
🌐 r/learnpython
18
2
July 28, 2022
Why was string.decode() removed in Python 3?
Python 3 has a much clearer separation between text (str type) and bytes (bytes type). Encoding turns text into bytes, and decoding turns bytes into text. Hence, only bytes has a .decode() method, and only str has a .encode() method. Some of the codecs in Python 2 didn't really fit this pattern; for example, str.decode('hex') basically takes in a series of characters that represent hexadecimal values, and returns some bytes with those hexadecimal values. This behavior doesn't fit into what I said above, so that's why in Python 3 you can only find it in the codecs module, which contains several things that aren't really proper text encodings (where encoding means text -> bytes and decoding means bytes -> text). However, I recommend avoiding these when possible because they are confusing. The binascii module has a function that does exactly what str.decode('hex') used to do: binascii.unhexlify() . This is what I would recommend using since it's much clearer about what it does (including better documented). (EDIT: Actually, u/K900_ 's suggested method (bytes.fromhex()) is maybe even clearer than this one... I would go with that instead. (I didn't realize it existed.)) More on reddit.com
🌐 r/learnpython
7
4
February 23, 2018
Python 3 - Encode/Decode vs Bytes/Str - Stack Overflow
I am new to python3, coming from python2, and I am a bit confused with unicode fundamentals. I've read some good posts, that made it all much clearer, however I see there are 2 methods on python 3,... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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 › library › stdtypes.html
Built-in Types — Python 3.14.5rc1 documentation
Otherwise, the bytes object underlying ... bytes.decode(). See Binary Sequence Types — bytes, bytearray, memoryview and Buffer Protocol for information on buffer objects. Passing a bytes object to str() without the encoding or errors arguments falls under the first case of returning the informal string representation (see also the -b command-line option to Python)...
🌐
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.
🌐
Decode Labs
decodelabs.tech
Decode Labs - Global Internship Opportunities | decodelabs.tech
Decode Labs helps learners worldwide gain practical project experience, guided mentorship, and verified outcomes that hiring teams value. ... Most popular tracks chosen by learners. ... Learn AI fundamentals, machine learning, and neural networks. Apply Now ... Master frontend and backend technologies for complete web solutions. Apply Now ... Learn Python from basics to advanced programming concepts.
Find elsewhere
🌐
W3Schools
w3schools.com › python › ref_os_fsdecode.asp
Python os.fsdecode() Method
Python Examples Python Compiler Python Exercises Python Quiz Python Challenges Python Server Python Syllabus Python Study Plan Python Interview Q&A Python Bootcamp Python Certificate Python Training · ❮ OS Module · Encode and decode file path: #Import os Library import os #Encode filename encode = os.fsencode("/home/testuser/desktop/newfile.txt") #Print the encoded filename print(encodedPath) #Print the decoded filename print(os.fsdecode(encodedPath)) Try it Yourself » ·
🌐
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.
🌐
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).
🌐
W3Schools
w3schools.com › python › python_json.asp
Python JSON
Python Variables Variable Names Assign Multiple Values Output Variables Global Variables Variable Exercises Code Challenge Python Data Types
🌐
Online Tools
emn178.github.io › online-tools › base64_decode.html
Base64 Decode - Online Tools
This online Base64 decoding tool helps you decode Base64 to text or binary. You can output UTF-8, UTF-16, Hex, or other encodings. It also supports various formats such as RFC 4648 (standard and URL Safe), RFC 2045 (MIME), RFC 2152 (UTF-7), and RFC 3501 (IMAP).
🌐
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():
🌐
timerring
blogs.timerring.com › posts › the-encode-and-decode-in-python
The Encode and Decode in Python | timerring
January 19, 2025 - And python will use the encoding type to transform every character in the string to the corresponding byte sequence. s = "你好,世界" encoded_s = s.encode('utf-8') print(encoded_s) # b'\xe4\xbd\xa0\xe5\xa5\xbd\xef\xbc\x8c\xe4\xb8\x96\xe7\x95\x8c' # the b is the prefix of the byte sequence. And the decode is the function of byte sequence.
🌐
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')
🌐
Python
wiki.python.org › moin › UnicodeDecodeError
UnicodeDecodeError
Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 0: ordinal not in range(128) Python 3000 will prohibit encoding of bytes, according to PEP 3137: "encoding always takes a Unicode string and returns a bytes sequence, and decoding always takes a bytes sequence and returns a Unicode string".
🌐
URLDecoder
urldecoder.io › python
URL Decoding query strings or form parameters in Python | URLDecoder
If you want to decode or parse multiple query strings of type application/x-www-form-urlencoded (e.g 'name=John+Doe&phone=+919999999999'), then you can use parse_qs or parse_qsl functions provided by urllib.parse package.
🌐
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:............................................................ ............................
🌐
Reddit
reddit.com › r/learnpython › why was string.decode() removed in python 3?
r/learnpython on Reddit: Why was string.decode() removed in Python 3?
February 23, 2018 -

I'm working on a project where I'm trying to get someone's old Python 2 code updated to work in Python 3, and one of the functions they used was "mystring.decode('hex'). Now I'm trying to figure out how to replicate this functionality in Python 3 and I'm having a hell of a time wrestling with it. Why did Python ditch this?

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.