Problems in API Request on request url with encoded characters

I’m using the frappe-docker found in github
I did introduced some Customer data via Dashboard. Some of the customers have the name with spanish accents.

Then i tried to request the API for the data of the customer with accent in name /api/resource/Customer/{customerName} customerName is Cafeter%C3%ADa%20Rigoberto%20S.L. (uri encoded)

The server responses with 500 http code and some text identifing the error.

The server console shows:

{my_ip} - - [30/Jan/2018 13:56:44] “GET /api/resource/Customer/Cafeter%C3%ADa%20Rigoberto%20S.L. HTTP/1.1” 500 -
13:56:44 web.1 | INFO:werkzeug:{my_ip} - - [30/Jan/2018 13:56:44] “GET /api/resource/Customer/Cafeter%C3%ADa%20Rigoberto%20S.L. HTTP/1.1” 500 -
13:56:44 web.1 | Traceback (most recent call last):
13:56:44 web.1 | File “/home/frappe/frappe-bench/apps/frappe/frappe/”, line 15, in call
13:56:44 web.1 | return super(StaticDataMiddleware, self).call(environ, start_response)
13:56:44 web.1 | File “/home/frappe/frappe-bench/env/lib/python2.7/site-packages/werkzeug/”, line 761, in call
13:56:44 web.1 | if path.startswith(search_path):
13:56:44 web.1 | UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xc3 in position 30: ordinal not in range(128)

What can i do?

You have two choices, either change ‘Cafetería’ to ‘Cafeteria’, or
precede the name with a u, like so u’Cafetería Rigoberto S.L.’

Possibly the second change will break something so you should test this. As well from what I can tell the name printed on invoices will be literally u’Cafetería Rigoberto S.L.’

The problem occurs since Python 2.7 uses ‘ascii’ string encoding that is unable to encode a string like ünicôdé whereas a unicode encoded string can do so.

This explains in detail python - How to fix: "UnicodeDecodeError: 'ascii' codec can't decode byte" - Stack Overflow

1 Like