davesteele / gnome-gmail

Integrate GMail into the Linux Desktop
https://davesteele.github.io/gnome-gmail/
GNU General Public License v2.0
50 stars 13 forks source link

UnicodeEncodeError: 'ascii' codec can't encode character #29

Closed simonbcn closed 8 years ago

simonbcn commented 8 years ago

Firefox 44.0.2 Arch Linux 64 bits

I'm trying to write an email from the link "Contact Developer" in this page: http://add0n.com/fastest-gmail.html but it shows this error:

Traceback (most recent call last):
  File "/usr/share/gnome-gmail/gnomegmail.py", line 809, in <module>
    main()
  File "/usr/share/gnome-gmail/gnomegmail.py", line 794, in main
    gmailurl = gm_url.gmail_url()
  File "/usr/share/gnome-gmail/gnomegmail.py", line 533, in gmail_url
    gmailurl = self.api_gmail_url()
  File "/usr/share/gnome-gmail/gnomegmail.py", line 500, in api_gmail_url
    gm_api.form_message()
  File "/usr/share/gnome-gmail/gnomegmail.py", line 311, in form_message
    self.message_text = msg.as_bytes()
  File "/usr/lib/python3.5/email/message.py", line 179, in as_bytes
    g.flatten(self, unixfrom=unixfrom)
  File "/usr/lib/python3.5/email/generator.py", line 115, in flatten
    self._write(msg)
  File "/usr/lib/python3.5/email/generator.py", line 181, in _write
    self._dispatch(msg)
  File "/usr/lib/python3.5/email/generator.py", line 214, in _dispatch
    meth(msg)
  File "/usr/lib/python3.5/email/generator.py", line 288, in _handle_multipart
    self._write_lines(preamble)
  File "/usr/lib/python3.5/email/generator.py", line 161, in _write_lines
    self.write(laststripped)
  File "/usr/lib/python3.5/email/generator.py", line 410, in write
    self._fp.write(s.encode('ascii', 'surrogateescape'))
UnicodeEncodeError: 'ascii' codec can't encode character '\xed' in position 18: ordinal not in range(128)

My locales:

LANG=es_ES.utf8
LC_CTYPE=es_ES.utf8
LC_NUMERIC="es_ES.utf8"
LC_TIME="es_ES.utf8"
LC_COLLATE=C
LC_MONETARY="es_ES.utf8"
LC_MESSAGES="es_ES.utf8"
LC_PAPER="es_ES.utf8"
LC_NAME="es_ES.utf8"
LC_ADDRESS="es_ES.utf8"
LC_TELEPHONE="es_ES.utf8"
LC_MEASUREMENT="es_ES.utf8"
LC_IDENTIFICATION="es_ES.utf8"
LC_ALL=
simonbcn commented 8 years ago

The default version of python in Arch is Python 3.5.1 If I execute python2 gnome-gmail.py it doesn't show the unicode error but it fails in oauth process. It opens my default browser (Firefox 44.0.2) with the oauth page but when I press "Allow", the browser closes and gnome-gmail shows an error "400: Bad Request".

simonbcn commented 8 years ago

If I execute, from console, gnome-gmail works and it opens the gmail URL in default browser but if I execute gnome-gmail any-text it fails.

davesteele commented 8 years ago

For the 400 error, note #10 and #22, patched in 2.0-1.

davesteele commented 8 years ago

./gnome-gmail launches a url in a browser. gnome-gmail any-text works with the GMail API, and thus needs OAuth2.

simonbcn commented 8 years ago

gnome-gmail is for python 3 or 2?

davesteele commented 8 years ago

Python 3 compatibility is recent, and not well tested.

simonbcn commented 8 years ago

Ok, I have changed /usr/bin/gnome-gmail to execute it with python2 and now it works well.

ghost commented 8 years ago

hi dave, an arch user of my package has encountered same error. but from console only, supposedly for the use of utf-8 or not. same spanish locale of simonbcn. culprit is the localization string of the preamble message '_("Mime message attached")' to "Mensaje MIME incluído": accented i except in "UnicodeEncodeError: 'ascii' codec can't encode character... bla bla" we are testing a patch that i will commit as soon as i have some positive feedback

ghost commented 8 years ago

pull https://github.com/davesteele/gnome-gmail/pull/43 this should be conclusive

simonbcn commented 8 years ago

It works for me.