UnicodeDecodeError, invalid continuation byte
In binary, 0xE9 looks like 1110 1001
. If you read about UTF-8 on Wikipedia, you’ll see that such a byte must be followed by two of the form 10xx xxxx
. So, for example:
>>> b'\xe9\x80\x80'.decode('utf-8')
u'\u9000'
But that’s just the mechanical cause of the exception. In this case, you have a string that is almost certainly encoded in latin 1. You can see how UTF-8 and latin 1 look different:
>>> u'\xe9'.encode('utf-8')
b'\xc3\xa9'
>>> u'\xe9'.encode('latin-1')
b'\xe9'
(Note, I'm using a mix of Python 2 and 3 representation here. The input is valid in any version of Python, but your Python interpreter is unlikely to actually show both unicode and byte strings in this way.)
python stdin: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xca in position 0: invalid continuation byte
Yes, I do. Let's look at your command line:
(venv) Test@Test-MacBookPro pythonProject1 % /Users/Test/PycharmProjects/pythonProject1/venv/bin/python /Users/Test/PycharmProjects/pythonProject1/proto_1.py < /Users/Test/PycharmProjects/pythonProject1/venv/bin/python /Users/Test/PycharmProjects/pythonProject1/input.txt
Removing the paths just to make it more clear:
python proto_1.py < python input.txt
You are passing the Python interpreter executable as your input file. Why did you do that? Just pass the file name:
/Users/Test/PycharmProjects/pythonProject1/venv/bin/python /Users/Test/PycharmProjects/pythonProject1/proto_1.py < /Users/Test/PycharmProjects/pythonProject1/input.txt
Got the error:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 1: invalid continuation byte, playsound
It seems that the file was written in a different encoding than what the playsound module is expecting.
If you have created the mp3 file yourself, maybe you have not chosen the right encoding.
Otherwise, it might be a bug of the playsound module.
Update:
The error message actually refers to the file path you are providing, not the file itself. As you are working on Windows and paths are build with backslashes, which are a special character in Python strings, you need to use either double backslashes instead of a single backslash as in
'C:\\Users\\hp\\Desktop\\francisco\\trabalhos que não são da escola\\musica.mp3'
or you provide the string as a raw string by putting an "r" before the first quotation mark, like this:
r'C:\Users\hp\Desktop\francisco\trabalhos que não são da escola\musica.mp3'
Update 2: Combining f-string and r-string
from pathlib import Path
Path(rf"{r'C:\Users'}").exists()
File "<ipython-input-45-dc9a3746d390>", line 1
Path(rf"{r'C:\Users'}").exists()
^
SyntaxError: f-string expression part cannot include a backslash
Path(rf"{'C:'}\{'Users'}").exists()
Out[46]: True
Path(fr"{'C:'}\{'Users'}").exists()
Out[47]: True
Django UnicodeDecodeError: 'utf-8' codec can't decode byte 0xcf in position 5: invalid continuation byte
Everything turned out to be far from django, I thought I changed the username to the end, but I had to go all the way to computer > properties > change properties and change full name, thank for you time
Related Topics
Pytest Running with Another Version of Python
Unicodeencodeerror: 'Charmap' Codec Can't Encode - Character Maps to <Undefined>, Print Function
Remove Duplicate Dict in List in Python
Converting a Pandas Groupby Output from Series to Dataframe
How Accurate Is Python's Time.Sleep()
How to See the Entire Http Request That's Being Sent by My Python Application
Find the Column Name Which Has the Maximum Value for Each Row
How to Know If an Object Has an Attribute in Python
Stripping Everything But Alphanumeric Chars from a String in Python
Creating a Range of Dates in Python
Tensorflow Install Fails with "Compiletime Version 3.5 of Module Does Not Match Runtime Version 3.6"
Are Python Variables Pointers? or Else, What Are They
How to Round to 2 Decimals with Python
What Is the Fastest Way to Send 100,000 Http Requests in Python
Converting a String Representation of a List into an Actual List Object
Import Error: No Module Name Urllib2
How to Catch and Print the Full Exception Traceback Without Halting/Exiting the Program