Answer the question
In order to leave comments, you need to log in
How to fix encoding issue (UnicodeEncodeError: 'latin-1' codec can't encode characters..) when interacting with mysql?
Hello!
The problem (at least) with entering information into the Mysql database.
I am getting an error:
UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-3: ordinal not in range(256)
Answer the question
In order to leave comments, you need to log in
if you leave these lines, then 0 or $ad_id is written,
what's wrong here??
0) If you yourself can’t understand what’s going on in the code, it’s better to hire a programmer. And don't go there yourself.
1) Your lines are incorrectly specified, these are 75 and 97 and not 83 and .
2) Line 97 does not affect anything. it starts with // which means that this is a comment and it is not executed
3) This comment says that $pending = 0 by default. If you delete it on line 75, then inside the add function it should be 0 by default. BUT the comment is not the code. Most likely you have changed the default value. See function add on the messages class in the "classes/messages.php" file.
4) next, you need to watch what happens in the above method (add) when $pending 1 or 0 is received.
There are no conditions associated with incorrect behavior in this code, and you most likely do not need to remove $pending = 0
So, the problem was not in the database and Python,
but in the language of the system (VPS / Ubuntu 18)
in which the Russian language was not installed at all.
Check system encoding:
import sys
import locale
print(sys.getfilesystemencoding())
print(locale.getpreferredencoding())
Yesterday I caught the same error on a freshly bought server with ubuntu 20. I launched a cart bot. Helped dpkg-reconfigure locales there we select all EN.UTF-8 and all Ru-RU. Then I manually wrote LANG=ru_RU.UTF and it all worked.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question