This error.
SyntaxError: Non-UTF-8 code starting with '\xe3' in file D:\Projetos\M74Chat\M74Chat\config.py on line 4, but no encoding decared;
see
https://peps.python.org/pep-0263/ for details
My code.
import psycopg2
connection made successfully, generates this error
# and cursor.execute('SELECT * FROM contact')
I don't believe the only solution to this problem is to put in all .py files on the first line: "# coding: utf-8", serious?
Please post code and complete error message, including the traceback.
\x is the start of an escape sequence for a unicode character. This should be followed by two digits that define the unicode character. \xe3 is a lower case "a" with tilde. I have no problem using in a program like this:
print("\\xe3 is a lower-case a with a tilde \xe3")
Notice that I do not specify the encoding of the source file. I am running windows 10 and python 3.11. What are you running?
Thanks, deanhystad.
I don't know exactly what happened after using
# coding = utf-8
I removed it from the code and it's working.
This my code:
import psycopg2
try:
# Conexão ao banco de dados
con = psycopg2.connect(dbname="*", user="*", password="*", host="*", port="*")
# Criando um cursor para executar comandos SQL
cursor = con.cursor()
connected to DB
# Executando uma consulta SQL
cursor.execute("SELECT * FROM contact")
# Obtendo os resultados da consulta
resultado = cursor.fetchall()
# Imprimindo os resultados
for linha in resultado:
print(linha)
# Fechando o cursor e a conexão
cursor.close()
con.close()
except Exception as e:
print("Erro ao conectar ao banco de dados: ", e)
The message in oder post.
How do you edit your files? I've noticed it is easy to confuse windows into thinking a file is latin1
Quote:The message in oder post.
That was the entire error message? Nothing else?
Aren't you using Python 2.7 instead of Python 3 ?
Also if you have a file encoded in some other encoding and you add # coding: utf8
at the top of the file, this may confuse the Python compiler.
(Mar-22-2024, 06:52 PM)deanhystad Wrote: [ -> ]How do you edit your files? I've noticed it is easy to confuse windows into thinking a file is latin1
Quote:The message in oder post.
That was the entire error message? Nothing else?
check image in Attachment.