Nekmo / amazon-dash

Hack your Amazon Dash to run what you want.
MIT License
816 stars 69 forks source link

not using utf8 by default #139

Closed fiws closed 5 years ago

fiws commented 5 years ago

What is the purpose of your issue?

Guideline for bug reports

You can delete this section if your report is not a bug

How to get your version:

amazon-dash --version
python --version
pip --version
easy_install --version

Description

I have utf8 characters in my config. amazon-dash does not like it and throws errors like this:

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.6/dist-packages/amazon_dash/listener.py", line 84, in execute
    result = self.execute_instance.execute(root_allowed)
  File "/usr/local/lib/python3.6/dist-packages/amazon_dash/execute.py", line 218, in execute
    **kwargs)
  File "/usr/lib/python3/dist-packages/requests/api.py", line 58, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 520, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 630, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 440, in send
    timeout=timeout
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 601, in urlopen
    chunked=chunked)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 357, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.6/http/client.py", line 1239, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.6/http/client.py", line 1284, in _send_request
    body = _encode(body, 'body')
  File "/usr/lib/python3.6/http/client.py", line 161, in _encode
    (name.title(), data[err.start:err.end], name)) from None
UnicodeEncodeError: 'latin-1' codec can't encode character '\u2019' in position 62: Body ('’') is not valid Latin-1. Use body.encode('utf-8') if you want to send it encoded in UTF-8.

What I Did

I've tried many workarounds. Nothing worked.

But somehow this all works on my raspberry with raspbian. I could not get it working on a fresh ubuntu vm or ubuntu container or arch on a raspberry pi.

Nekmo commented 5 years ago

Maybe the problem is with the server. Check the accepted encodings.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Charset

fiws commented 5 years ago

The server is slack.. so there is nothing i can do there. And the errors also looks like its client side. I fixed my problem with #140

Nekmo commented 5 years ago

It seems to be a known issue in the request documentation, but can be solved using bytes. https://github.com/kennethreitz/requests/issues/4503

It should be safe to use utf-8 in this context. Thanks!