pombreda / gcalcli

Automatically exported from code.google.com/p/gcalcli
0 stars 0 forks source link

UnicodeEncodeError #10

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Run:

$ gcalcli --user user --pw password agenda

What is the expected output? What do you see instead?

---
Current Time: Thu Oct  4 09:51:27 2007

Agenda for [ Thu Oct  4 00:00:00 2007 <-> Tue Oct  9 00:00:00 2007 ]

Thu Oct 04   4:00    Happy Hour

Fri Oct 05Traceback (most recent call last):
  File "/cygdrive/c/Documents and Settings/fi326c/My
Documents/bin/gcalcli", line 619, in <module>
    DoooooItHippieMonster()
  File "/cygdrive/c/Documents and Settings/fi326c/My
Documents/bin/gcalcli", line 584, in DoooooItHippieMonster
    GoogleCalendar(usr, pwd, access, details).DateQuery()
  File "/cygdrive/c/Documents and Settings/fi326c/My
Documents/bin/gcalcli", line 464, in DateQuery
    self._PrintEvents(now, eventList)
  File "/cygdrive/c/Documents and Settings/fi326c/My
Documents/bin/gcalcli", line 303, in _PrintEvents
    '  %-7s  %s\n' % (tmpTimeStr, event.title.text))
  File "/cygdrive/c/Documents and Settings/fi326c/My
Documents/bin/gcalcli", line 174, in PrintMsg
    sys.stdout.write(msg)
  File "/usr/lib/python2.5/codecs.py", line 303, in write
    data, consumed = self.encode(object, self.errors)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in
position 38: ordinal not in range(128)

---

What version of the product are you using? 

gcalcli-1.2
python-dateutil-1.2
gdata.py-1.0.8

On what operating system?

$ uname -a
CYGWIN_NT-5.1 A3843457 1.5.24(0.156/4/2) 2007-01-31 10:57 i686 Cygwin

Please provide any additional information below.

$ python -V
Python 2.5.1

Original issue reported on code.google.com by iliyan.j...@gmail.com on 4 Oct 2007 at 3:05

GoogleCodeExporter commented 9 years ago

Original comment by insa...@gmail.com on 5 Oct 2007 at 5:25

GoogleCodeExporter commented 9 years ago
In order for me to reproduce this problem could you create a new public 
calendar and
duplicate the event on it.  Then I'll subscribe and see what's up with this 
unicode
issue...

Original comment by insa...@gmail.com on 8 Oct 2007 at 2:23

GoogleCodeExporter commented 9 years ago
I'm having the same problem. You can reproduce it by using å, ä or ö in an 
event. Do
you know of some quick fix to this problem, or will we have to wait for it to
hopefully be resolved in the next version?

Original comment by niklas.b...@gmail.com on 23 Oct 2007 at 12:14

GoogleCodeExporter commented 9 years ago
Forgot to mention that I found a solution to this problem. change "sys.stdout =
codecs.getwriter(locale.getpreferredencoding())(sys.stdout)" on line 66 to
"sys.stdout = codecs.getwriter('utf-8')(sys.stdout)". This sets the character
encoding to UTF-8. You might want use UTF-8 for input as well - do this by 
changing
line 67 to "sys.stdin = codecs.getreader('utf-8')(sys.stdin)"

Original comment by niklas.b...@gmail.com on 5 Nov 2007 at 6:32

GoogleCodeExporter commented 9 years ago
I have the same problem. The changes proposed by Niklas does not fix the 
problem for
me. This unfortunately makes gcalcli unusable for me...

Original comment by DanielLi...@gmail.com on 14 Jan 2008 at 2:05

GoogleCodeExporter commented 9 years ago
In gcalcli you could had :
import atom
atom.XML_STRING_ENCODING = None

It works for me...

Original comment by tho...@montfort.fr on 30 Jan 2008 at 10:06

GoogleCodeExporter commented 9 years ago
I have the same problem, and after I remove the two lines:
sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
sys.stdin = codecs.getreader(locale.getpreferredencoding())(sys.stdin)

then it works.

Original comment by liuzhong...@gmail.com on 28 Mar 2008 at 8:49

GoogleCodeExporter commented 9 years ago
I have another workaround:
Put following lines into site-packages/sitecustomize.py
see http://www.faqs.org/docs/diveintopython/kgp_unicode.html

import os, sys
if 'UTF-8' in os.environ['LANG']:
    sys.setdefaultencoding('utf-8')

Original comment by kuang...@gmail.com on 10 May 2008 at 10:55

GoogleCodeExporter commented 9 years ago
I had a similar problem but with UnicodeDecodeError.  Doing

import atom
atom.XML_STRING_ENCODING = None
atom.XML_STRING_DECODING = None

Fixed it for me

Original comment by Quazie on 18 May 2008 at 5:36

GoogleCodeExporter commented 9 years ago
Still does not work for me. Have changed the stdin &stdut lines as suggested 
here and
added the imort atom at the beginning of the script.

Here's the result of 'gcalcli --cals owner calw':
"UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 48: 
ordinal not
in range(128)"

Any more hints?

Original comment by h3L93.ph1l1pp@gmail.com on 30 Jun 2008 at 5:28

GoogleCodeExporter commented 9 years ago
Would it help if I set up a brand new calendar for you, insanum, to reproduce 
the error?

Original comment by h3L93.ph1l1pp@gmail.com on 23 Jul 2008 at 7:11

GoogleCodeExporter commented 9 years ago
Yet another fix?

Modified PrintMsg as follows:

def PrintMsg(color, msg):
    if CLR.useColor:
        sys.stdout.write(str(color))
        sys.stdout.write(unicode(msg, errors="ignore"))
        sys.stdout.write(str(CLR_NRM()))
    else:
        sys.stdout.write(unicode(msg, errors="ignore"))

Cheers,
Matt

Original comment by mbaker....@gmail.com on 10 Mar 2009 at 11:44

GoogleCodeExporter commented 9 years ago
mbaker.pdx seems to have the best result for me, it also seems to be truest to 
what
the output is expected to be.

Thanks,
Stefan

Original comment by iamnafets on 1 Apr 2009 at 11:38

GoogleCodeExporter commented 9 years ago
default sys.stdout can write string
the alternate sys.stdout 
codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
can write unicode, but msg is a string (not unicode) so we have either to use 
the
standard sys.stdout, or convert it back to unicode and use:
sys.stdout.write(unicode(msg,locale.getpreferredencoding()))

If you use utf-8 just commenting the two initial lines
sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
sys.stdin = codecs.getreader(locale.getpreferredencoding())(sys.stdin)
must work,

If you have to switch encoding between the calendar and your console you will
probably have to reencode the msg.

Original comment by marc.zon...@gmail.com on 15 Apr 2009 at 5:52

GoogleCodeExporter commented 9 years ago
mbaker.pdx's modification to PrintMsg() does indeed get rid of the error for 
me, but
the Japanese characters present in my calendar items are not displayed (they 
are blank).

Original comment by tacomana...@gmail.com on 20 May 2009 at 6:25

GoogleCodeExporter commented 9 years ago
Kuangche's solution (see comment 8) should be the most elegant one. Works for me
well. (Though I had to add the lines to /etc/python2.6/sitecustomize.py). thx.

Original comment by lupusinclitos on 14 Jul 2009 at 10:32

GoogleCodeExporter commented 9 years ago
Comment 4 worked for me.  Freebsd 7.2 i386, Python 2.6.2, gcalcli 1.4.2.
None of the others did.
Thanks.

Original comment by vvaauugg...@gmail.com on 4 Nov 2009 at 11:38

GoogleCodeExporter commented 9 years ago
I confirme that adding:

import os, sys
if 'UTF-8' in os.environ['LANG']:
    sys.setdefaultencoding('utf-8')

to /etc/python2.6/sitecustomize.py resolved my issue.

I also tried a lot of other workaround that worked some of the times but not 
always.
This one is the moste stable. It worked on a unmodified version of gcalcli 
1.4.1 on
ubuntu 9.04.

Original comment by bastien...@gmail.com on 4 Dec 2009 at 10:31

GoogleCodeExporter commented 9 years ago
I confirm that commenting out lines 66 and 67 (sys.std...) worked for me.

v1.4
gentoo

Original comment by gross.jo...@gmail.com on 11 Feb 2010 at 11:12

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Commented out lines 66 and 67 as well, worked.

Yet, when using a ‘cal’ command, the columns separators are broken if a 
line contains
special characters, since it obviously calculates a width of 2 characters for 
one
“special” unicode character.

Original comment by jfgr...@gmail.com on 11 May 2010 at 10:13

GoogleCodeExporter commented 9 years ago
Same error with gcalcli 1.4-4 and python2 2.7.1.

The problem: I don't have a sitecustomize.py ^^

Original comment by thms.eb...@gmail.com on 15 Feb 2011 at 5:08

GoogleCodeExporter commented 9 years ago
Comment 12 fixed the issue for me.

Original comment by schara...@gmail.com on 11 Jul 2011 at 8:34

GoogleCodeExporter commented 9 years ago

Original comment by eda...@insanum.com on 31 Jul 2011 at 8:15

GoogleCodeExporter commented 9 years ago
Issue 18 has been merged into this issue.

Original comment by eda...@insanum.com on 31 Jul 2011 at 5:19

GoogleCodeExporter commented 9 years ago
Issue 29 has been merged into this issue.

Original comment by eda...@insanum.com on 31 Jul 2011 at 5:20

GoogleCodeExporter commented 9 years ago
Issue 31 has been merged into this issue.

Original comment by eda...@insanum.com on 31 Jul 2011 at 5:24

GoogleCodeExporter commented 9 years ago
Issue 39 has been merged into this issue.

Original comment by eda...@insanum.com on 31 Jul 2011 at 5:25

GoogleCodeExporter commented 9 years ago
Issue 41 has been merged into this issue.

Original comment by eda...@insanum.com on 31 Jul 2011 at 5:25

GoogleCodeExporter commented 9 years ago
Issue 67 has been merged into this issue.

Original comment by eda...@insanum.com on 31 Jul 2011 at 5:26

GoogleCodeExporter commented 9 years ago
Fixed for the most part.  There is still an issue with wider east asian 
characters in the calw and calm output.  A patch for an older version of 
gcalcli can be found in issue 31.

I'm closing this issue out and opening a new one specifically for east asian 
characters. 

Original comment by eda...@insanum.com on 2 Aug 2011 at 6:04

GoogleCodeExporter commented 9 years ago
I still have this problem. No wider east Asian characters.

gcalcli 2.1
Python 2.7
elementtree-1.2.7-20070827
gdata-2.0.14
python-dateutil-1.5

Original comment by erik.westrup on 7 Sep 2011 at 11:18

GoogleCodeExporter commented 9 years ago
Please open a new issue specifically for v2.1 of gcalcli.  Provide the 
resulting stack trace and most importantly, create and share a calendar which 
contains an event that exposes your problem.  Thanks.

My tests didn't expose a problem so there must be an edge case you're 
experiencing.

Original comment by eda...@insanum.com on 7 Sep 2011 at 11:29