windows

Problems inserting utf8 data to PostgreSQL with Python  #angularjs #reactjs

  • python windows postgresql encoding utf-8
  • The stack trace does not output anything, I get no error in python.
  • When I do the same insert through my python script the name appears in my database as B°rre.
  • query = “INSERT INTO name (surname) VALUES (%s) RETURNING id” data = (‘børre’.
  • Browse other questions tagged python windows postgresql encoding utf-8 or ask your own question .

Originally I tried to encode my PSQL DB as utf-8, then manually tried to insert the characters that would be of a problem like this:

@ng_real_ninja: Problems inserting utf8 data to PostgreSQL with Python #angularjs #reactjs

I am reading scandinavian language websites with a web-crawler – and wish to insert them into my PostgreSQL database.

Originally I tried to encode my PSQL DB as utf-8, then manually tried to insert the characters that would be of a problem like this:

This was done in the windows PSQL shell.

This gave me the following error: ERROR: invalid byte sequence for encoding “UTF8”: 0x9b. So after doing some googling I changed the client encoding to latin1. Now that statement was successfull. The server encoding is still utf8.

When I do the same insert through my python script the name appears in my database as B°rre. If I change back the encoding of client to utf8, I also get entries with wrong special characters.

My python script is utf8 encoded, but prints the name correct.

Insert statement:

As previously stated, print(personObject.surname) gives ‘Børre’

If I try the following:

I get the following in my database:

\x62c383c2b8727265

Why don’t you use UTF-8 encoding? Today, there exists no reason not to use it. – Daniel 5 hours ago

The code fragment you have at the top should work.

. It looks to me like python thinks your script is not wtitten is UTF8, but instead some other codepage.

windows

You might also like More from author

Comments are closed, but trackbacks and pingbacks are open.