Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32917

Re: Right solution to unicode error?

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <oscar.j.benjamin@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'debugging': 0.05; 'ascii': 0.07; 'problem?': 0.07; 'properly.': 0.07; 'python': 0.09; 'anders': 0.09; 'encode': 0.09; 'cc:addr:python-list': 0.10; 'subject:error': 0.11; 'encoding': 0.15; '66,': 0.16; 'codec': 0.16; 'ordinal': 0.16; 'repr()': 0.16; 'subject:unicode': 0.16; 'utf-8)': 0.16; 'string': 0.17; 'wrote:': 0.17; 'fix': 0.17; 'script.': 0.17; 'unicode': 0.17; 'windows': 0.19; 'file.': 0.20; 'parse': 0.22; 'cc:2**0': 0.23; 'purposes': 0.23; 'cc:no real name:2**0': 0.24; 'script': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'skip:" 20': 0.26; '(most': 0.27; '(such': 0.27; 'message-id:@mail.gmail.com': 0.27; 'fine': 0.28; 'character': 0.29; "i'm": 0.29; 'received:209.85.215.46': 0.30; 'code': 0.31; 'file': 0.32; 'print': 0.32; 'getting': 0.33; 'traceback': 0.33; 'that,': 0.34; "can't": 0.34; 'received:google.com': 0.34; 'whatever': 0.35; 'so,': 0.35; 'subject:?': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'really': 0.36; 'characters': 0.36; 'should': 0.36; 'does': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'page': 0.38; 'where': 0.40; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'your': 0.60; 'skip:u 10': 0.60; 'containing': 0.61; 'telling': 0.61; 'tasks.': 0.65; 'subject': 0.66; '(standard': 0.84; 'oscar': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=HYG9pdYjHYlrgi32b5Zh13FiWr6zJYn6DI9jkB3gEHc=; b=kDLbT5Agh3sqnsM9HkayTKE23EnjTO1IWDVrycd3/A3Hsr7YP8YD1B/zSdFm7nCNST 7wUvOIbaBtk8DpNRSwhLR3Fhn/N7By2ksaYNpiC2Hx50Cd6jvra3IrGVhXSK+TJ4UWc5 fNjkKRfLG3K6p4w343G6hMFu9knnt/0ZGR38vLrsomXSKcxssQtsuT4MYH5buqW3HVXc gzALsTRKLz9SLE/sDaNPAexhFg4Ehq110rX88ACSVtL3ssdoTrgTrAtJYXZ3U4DUIwgF oGb1ry1r2pMXyE8O/o9zrpkmf/7jbfrijmwHri5smUmE3CO6EilpmpXsZpcuvObTkl20 iY6g==
MIME-Version 1.0
In-Reply-To <09a3d20b-5871-47f4-9218-df119698e405@m4g2000yqf.googlegroups.com>
References <09a3d20b-5871-47f4-9218-df119698e405@m4g2000yqf.googlegroups.com>
Date Wed, 7 Nov 2012 23:27:17 +0000
Subject Re: Right solution to unicode error?
From Oscar Benjamin <oscar.j.benjamin@gmail.com>
To Anders <aschneiderman@asha.org>
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3406.1352330840.27098.python-list@python.org> (permalink)
Lines 33
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1352330840 news.xs4all.nl 6842 [2001:888:2000:d::a6]:49249
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:32917

Show key headers only | View raw


On 7 November 2012 22:17, Anders <aschneiderman@asha.org> wrote:
>
> Traceback (most recent call last):
>   File "outlook_tasks.py", line 66, in <module>
>     my_tasks.dump_today_tasks()
>   File "C:\Users\Anders\code\Task List\tasks.py", line 29, in
> dump_today_tasks
>     print task.subject
> UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in
> position 42: ordinal not in range(128)
>
> Here's where I'm getting stuck.  In the code above I was just printing
> the subject so I can see whether the script is working properly.
> Ultimately what I want to do is parse the tasks I'm interested in and
> then create an HTML file containing those tasks.  Given that, what's
> the best way to fix this problem?

Are you using cmd.exe (standard Windows terminal)? If so, it does not
support unicode and Python is telling you that it cannot encode the
string in a way that can be understood by your terminal. You can try
using chcp to set the code page to something that works with your
script.

If you are only printing it for debugging purposes you can just print
the repr() of the string which will be ascii and will come out fine in
your terminal. If you want to write it to a html file you should
encode the string with whatever encoding (probably utf-8) you use in
the html file. If you really just want your script to be able to print
unicode characters then you need to use something other than cmd.exe
(such as IDLE).


Oscar

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Right solution to unicode error? Anders <aschneiderman@asha.org> - 2012-11-07 14:17 -0800
  RE: Right solution to unicode error? "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-11-07 23:07 +0000
  Re: Right solution to unicode error? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-11-07 23:27 +0000
  Re: Right solution to unicode error? Andrew Berg <bahamutzero8825@gmail.com> - 2012-11-07 17:51 -0600
  Re: Right solution to unicode error? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-11-07 23:53 +0000
    Re: Right solution to unicode error? Hans Mulder <hansmu@xs4all.nl> - 2012-11-08 12:40 +0100
  Re: Right solution to unicode error? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-11-08 00:44 +0000
  Re: Right solution to unicode error? wxjmfauth@gmail.com - 2012-11-08 03:01 -0800
  RE: Right solution to unicode error? Anders Schneiderman <ASchneiderman@asha.org> - 2012-11-08 09:00 -0500
  Re: Right solution to unicode error? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-11-08 14:06 +0000
    Re: Right solution to unicode error? wxjmfauth@gmail.com - 2012-11-08 07:05 -0800
      Re: Right solution to unicode error? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-11-08 18:32 +0000
        Re: Right solution to unicode error? wxjmfauth@gmail.com - 2012-11-08 11:30 -0800
        Re: Right solution to unicode error? wxjmfauth@gmail.com - 2012-11-08 11:30 -0800
      Re: Right solution to unicode error? Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-08 11:48 -0700
        Re: Right solution to unicode error? wxjmfauth@gmail.com - 2012-11-08 11:54 -0800
          Re: Right solution to unicode error? Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-08 13:41 -0700
            Re: Right solution to unicode error? wxjmfauth@gmail.com - 2012-11-09 02:06 -0800
          RE: Right solution to unicode error? "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-11-08 20:54 +0000
          Re: Right solution to unicode error? Ian Kelly <ian.g.kelly@gmail.com> - 2012-11-08 14:07 -0700
          Re: Right solution to unicode error? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2012-11-08 21:37 +0000
        Re: Right solution to unicode error? wxjmfauth@gmail.com - 2012-11-08 11:54 -0800
  Re: Right solution to unicode error? Andrew Berg <bahamutzero8825@gmail.com> - 2012-11-08 21:30 -0600

csiph-web