npinto / mail-trends

mail-trends (maintained github fork)
26 stars 7 forks source link

UnicodeDecodeError #7

Open mapopescu opened 12 years ago

mapopescu commented 12 years ago

Hi,

Thanks for the great work so far!

I had this error: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 152: ordinal not in range(128)

I am using an account with 2-steps authentication (sign in OK). My system is Windows 7 32 bit English, Python 2.7.

I modified one file messageinfo.py newestMessageSec = time.mktime([1970, 1, 1, 0, 0, 0, 0, 0, 0]) -> newestMessageSec = time.mktime([1980, 1, 1, 0, 0, 0, 0, 0, 0])

Here is the full error message: .. [2012-01-30 16:37:21,589] Logging out [2012-01-30 16:37:22,026] Identifying "me" messages Traceback (most recent call last): File "main.py", line 251, in message_infos = GetMessageInfos(opts) File "main.py", line 102, in GetMessageInfos for name, address in message_info.GetRecipients(): File "D:\Marius\npinto-mail-trends\messageinfo.py", line 81, in GetRecipients tos + ccs + resent_tos + resent_ccs) File "d:\python27\lib\email\utils.py", line 106, in getaddresses all = COMMASPACE.join(fieldvalues) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 152: ordinal not in range(128)

Thanks again, Marius

npinto commented 12 years ago

Marius,

What is the output of locale on your machine ?

N

mapopescu commented 12 years ago

Nicolas,


(None, None) 

> > > locale.getdefaultlocale()
> > > ('fr_FR', 'cp1252')
> > > locale.localeconv()
> > > {'mon_decimal_point': '', 'int_frac_digits': 127, 'p_sep_by_space': 127, 'frac_d
> > > igits': 127, 'thousands_sep': '', 'n_sign_posn': 127, 'decimal_point': '.', 'int
> > > _curr_symbol': '', 'n_cs_precedes': 127, 'p_sign_posn': 127, 'mon_thousands_sep'
> > > : '', 'negative_sign': '', 'currency_symbol': '', 'n_sep_by_space': 127, 'mon_gr
> > > ouping': [], 'p_cs_precedes': 127, 'positive_sign': '', 'grouping': []}```

Is this what you need?

Marius
npinto commented 12 years ago

This looks like a locale problem. Please update to include Unicode (UTF-8), e.g. fr_FR.UTF-8

mapopescu commented 12 years ago

Hi,

I guess you mean calling setlocale. It doesn't work with fr_FR.UTF-8, nor with >>> locale.setlocale(locale.LC_CTYPE, 'fr_FR.ISO8859-1') locale.Error: unsupported locale setting

I tried, this is the one that works:


'French_France.1252'

> > > locale.getlocale()
> > > ('fr_FR', 'cp1252')```

Thanks for your help, I'll try again the whole script using this locale.

Marius
mapopescu commented 12 years ago

I just tried again, same error. Probably I need to find out how to choose a Unicode locale in Windows. I tried all aliases I found in my locale.py file, all Unicode french ones don't work, unsupported locale.

Another track I'm looking at is to add decoding of the headers before calling email.utils.getaddresses in message_info.GetRecipients(): all_recipients = email.utils.getaddresses( tos + ccs + resent_tos + resent_ccs) maybe using pyzmail.

I'll take a look after my holiday, in about 2 weeks.

Marius

npinto commented 12 years ago

Ok let me know how it goes, it's hard for me to debug this since I don't use Windows.

ngulden commented 11 years ago

Hi,

I have the same error: [2013-03-30 19:35:37,560] Logging out [2013-03-30 19:35:37,854] Identifying "me" messages Traceback (most recent call last): File "main.py", line 251, in message_infos = GetMessageInfos(opts) File "main.py", line 102, in GetMessageInfos for name, address in message_info.GetRecipients(): File "/home/nico/dev/src/mail-trends/messageinfo.py", line 81, in GetRecipients tos + ccs + resent_tos + resent_ccs) File "/usr/lib/python2.7/email/utils.py", line 106, in getaddresses all = COMMASPACE.join(fieldvalues) UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 152: ordinal not in range(128)

My system: Debian Testing. Python 2.7.3. echo $LANG → de_DE.UTF-8

import locale locale.getdefaultlocale() ('de_DE', 'UTF-8')

ngulden commented 11 years ago

Update: I just saw, I checked out the original repository. Trying your checkout, the problem does not occur as reported. Everything seems fine for me. Thanks.