jbingel / lexi-server

6 stars 5 forks source link

Encoding problems in database calls #3

Open jbingel opened 5 years ago

jbingel commented 5 years ago

See for instance below error. Something wrong with invalid byte sequences.

2018-12-15 20:53:41,280 - lexi - {database.py:35} INFO - PSQL query: SELECT user_id FROM users WHERE email='joabingel@gmail.com'
2018-12-15 20:53:41,281 - lexi - {run_lexi_server.py:130} ERROR - invalid byte sequence for encoding "UTF8": 0xe4 0x45 0x4c

2018-12-15 20:53:41,282 - lexi - {run_lexi_server.py:131} ERROR - Traceback (most recent call last):
  File "/var/www/lexi/lexi-venv/lib/python3.5/site-packages/flask/app.py", line 1612, in full_dispatch_request
    rv = self.dispatch_request()
  File "/var/www/lexi/lexi-venv/lib/python3.5/site-packages/flask/app.py", line 1598, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/var/www/lexi/lexi/server/run_lexi_server.py", line 269, in test_connection
    working_fine = db_connection.test_connection()
  File "/var/www/lexi/lexi/server/util/database.py", line 27, in test_connection
    self.execute_and_fetchone(test_query)
  File "/var/www/lexi/lexi/server/util/database.py", line 45, in execute_and_fetchone
    self.execute(query, log)
  File "/var/www/lexi/lexi/server/util/database.py", line 36, in execute
    self.cursor.execute(query)
psycopg2.DatabaseError: invalid byte sequence for encoding "UTF8": 0xe4 0x45 0x4c
Joanv12 commented 4 years ago

Hi, I had the same problem. Could you solve it?

jbingel commented 4 years ago

Hi Joan,

it's not part of this repository, but I could solve the problem by using prepared statements following the instructions here: https://pynative.com/python-mysql-execute-parameterized-query-using-prepared-statement/

I've also moved from Postgres to MySQL, but I'd assume the former has the same functionality.

Joanv12 commented 4 years ago

Hi,

Thanks for the info. I managed to solve the problem. The error was due to the code in the database connection driver and had to close the connection at the end.