mrr_robot
(Pete Best)
27 October 2021 06:11
1
@{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.
mrr_robot
(Pete Best)
27 October 2021 07:09
3
I am using DatabaseLibrary
mrr_robot
(Pete Best)
27 October 2021 07:10
4
mrr_robot
(Pete Best)
27 October 2021 07:15
5
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?
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.
mrr_robot
(Pete Best)
27 October 2021 08:20
9
PostgreSQL Database (utf8)
mrr_robot
(Pete Best)
27 October 2021 10:55
10
I thought this would have been a problem that many have faced and the solution would have been easy
@{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}]
mrr_robot
(Pete Best)
28 October 2021 05:22
11
No quick solution to this problem
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?
mrr_robot
(Pete Best)
28 October 2021 09:04
12
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
mrr_robot
(Pete Best)
29 October 2021 05:37
13
Ok, now getting close to solve this.
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
mrr_robot
(Pete Best)
29 October 2021 06:09
14
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.