Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'latin-1' codec can't encode character #19

Open
GeirFrimann opened this issue Nov 7, 2021 · 1 comment
Open

'latin-1' codec can't encode character #19

GeirFrimann opened this issue Nov 7, 2021 · 1 comment

Comments

@GeirFrimann
Copy link

GeirFrimann commented Nov 7, 2021

I've created a REST API call from Thingsboard with the following included header:
Content-Type: application/json;charset=iso-8859-1 (tried with utf-8 as well)

Whenever any of the params for the sos-access contains swedish characters öäå, the lamda function raises this exception
(in this case for the letter å):
{
"errorMessage": "'latin-1' codec can't encode character '\\uffe5' in position 510: ordinal not in range(256)",
"errorType": "UnicodeEncodeError",
"stackTrace": [" File "/var/task/lambda_function.py", line 115, in lambda_handler\n AlarmResponse = client.send_alarm(\n", " File "/var/task/sos_access/client.py", line 176, in send_alarm\n return self._send_alarm(alarm_request)\n", " File "/var/task/sos_access/decorators.py", line 35, in retried_func\n result = func(*args, **kwargs)\n", " File "/var/task/sos_access/client.py", line 251, in _send_alarm\n alarm_response = self.transmit(\n", " File "/var/task/sos_access/client.py", line 367, in transmit\n transport.send(data.encode(self.ENCODING))\n"]
}

@Krolken
Copy link
Contributor

Krolken commented Nov 8, 2021

I think you have an encoding/decoding error a bit up in your application.

\uffe5 Seems to be unicode for the "yen-sign",

print("\uffe5")
>

Encoding åäö is possibe in latin-1 (iso-8859-1)

"åäö".encode('latin-1')
b'\xe5\xe4\xf6'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants