UnicodeDecodeError: 'ascii' codec can't decode

@{query_result}= Query ${sql}
=> UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xc3 in position 6: ordinal not in range(128)

When doing query and database has “öäå”, this problem occurs.

Could someone give simple solution how to fix this…how&where to enter “Encode String To Bytes” if that is the correct answer to solve this problem?

Without information on what library you are using it will be hard to answer your question.

I am using DatabaseLibrary

https://franz-see.github.io/Robotframework-Database-Library/api/0.5/DatabaseLibrary.html

robotframework-databaselibrary 1.2.4

Hmm, looking through the source a bit I do see references to ascii decoding for Python 2. Are you on Python 2 or 3?

Python 3.9.6

What type of database is the target DB? There’s also something about dbCharset in connect_to_database but that’s only for MySQLdb / pymysql.

PostgreSQL Database (utf8)

I thought this would have been a problem that many have faced and the solution would have been easy :frowning:

@{query_result}= Query ${sql}

Should I do some encoding/decoding/convert to bytes/… before I run this keyword?

Or should it be done(can it be done with RF) inside this keyword like:
@{query_result}= Convert[Query ${sql}]

No quick solution to this problem :frowning:

Little bit lost where the problem is located

Using Database library (Query) to get data from PostgreSQL Database with Robot Framework

Everything works fine where there is no “öäå” letter’s in data.

Any idea how to tackle this problem?

Just guessing here…
Psycopg 3 – PostgreSQL database adapter for Python

Could this be worth of try? Or this can break even the working test’s :frowning:

Ok, now getting close to solve this. :slight_smile:

When I created connevtion with py file and used:
conn = psycopg2.connect(**params)
cur = conn.cursor()
conn.set_client_encoding(‘UTF8’)

It will work.

So how can I set this conn.set_client_encoding(‘UTF8’) when using
Connect To Database
https://franz-see.github.io/Robotframework-Database-Library/api/0.5/DatabaseLibrary.html

Set Default Configuration
encoding=utf-8
encoding_errors=ignore

This settings does not help.
Shouldn’t Robot Framework use this SSH connection when this one is first created and database connection afterwards?

Robot Framework does not really come into play here. It might be an issue with the DatabaseLibrary though, so perhaps you can raise an issue in their repo.