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


Groups > comp.lang.python > #32912

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!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ramit.prasad@jpmorgan.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'error:': 0.05; 'failing': 0.05; 'ascii': 0.07; 'completeness': 0.07; 'problem?': 0.07; 'properly.': 0.07; 'python': 0.09; 'anders': 0.09; 'codecs': 0.09; 'encode': 0.09; 'lost.': 0.09; 'non-ascii': 0.09; 'received:155': 0.09; 'subject:error': 0.11; '(where': 0.15; '66,': 0.16; 'codec': 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'from:addr:jpmorgan.com': 0.16; 'i.e.,': 0.16; 'ordinal': 0.16; 'received:155.180': 0.16; 'received:159.53': 0.16; 'received:bankone.net': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'received:svr.bankone.net': 0.16; 'securities,': 0.16; 'subject:unicode': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; 'wrote:': 0.17; 'fix': 0.17; 'unicode': 0.17; 'previously': 0.18; 'to:name:python-list@python.org': 0.20; 'trying': 0.21; 'parse': 0.22; 'task': 0.23; 'to:2**1': 0.23; "i've": 0.23; 'received:169.254': 0.24; 'script': 0.24; 'tried': 0.25; 'header :In-Reply-To:1': 0.25; 'skip:" 20': 0.26; '(most': 0.27; '(as': 0.27; '2.6': 0.27; 'accuracy': 0.27; 'outlook': 0.28; 'run': 0.28; 'character': 0.29; 'convert': 0.29; 'objects': 0.29; 'received:169': 0.29; "i'm": 0.29; 'e.g.': 0.30; 'link.': 0.30; 'error': 0.30; 'figure': 0.30; 'code': 0.31; 'url:python': 0.32; 'file': 0.32; 'print': 0.32; 'getting': 0.33; 'docs': 0.33; 'traceback': 0.33; 'problem': 0.33; 'to:addr:python-list': 0.33; 'that,': 0.34; "can't": 0.34; 'list': 0.35; 'clear': 0.35; 'doing': 0.35; 'subject:?': 0.35; 'something': 0.35; 'list.': 0.35; 'but': 0.36; 'url:org': 0.36; 'characters': 0.36; 'url:library': 0.36; 'charset:us-ascii': 0.36; 'display': 0.36; 'subject:: ': 0.38; 'store': 0.38; 'supports': 0.38; 'some': 0.38; 'url:docs': 0.38; 'description': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'skip:" 10': 0.40; 'skip:u 10': 0.60; 'containing': 0.61; 'telling': 0.61; 'free': 0.61; 'information,': 0.63; 'url:email': 0.63; 'legal': 0.65; 'results': 0.65; 'tasks.': 0.65; 'subject': 0.66; 'purchase': 0.67; 'sale': 0.76; 'received:169.254.8': 0.84; 'aka': 0.91; 'online,': 0.98
X-DKIM OpenDKIM Filter v2.1.3 sf1.jpmchase.com qA7N8pSh018698
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=jpmorgan.com; s=smtpout; t=1352329731; bh=DfxAW0QOilK1l2W8KtkH9OTNG+i5pC9M7cZPX9w34KI=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=KlMFJ29vELQ1tmf5tEo4uYeVhJ7082CjTv9Te1xYapRagw4Bkc42TMyT6JbYZ5z9G 1rrkwD2uQVKWhy37K55egd5iT0wKN9IuMqFTGpznfoqxf3l3WfkyJpBcV9ERAcn7jv 0PbltJ4D3YMnhCPc8DUqYIHBCP/hQzYhMGOXQ1cQ=
From "Prasad, Ramit" <ramit.prasad@jpmorgan.com>
To Anders <aschneiderman@asha.org>, "python-list@python.org" <python-list@python.org>
Subject RE: Right solution to unicode error?
Thread-Topic Right solution to unicode error?
Thread-Index AQHNvTeM/xR6HEvFT06wM53mT6A/j5fe/e2A
Date Wed, 7 Nov 2012 23:07:33 +0000
References <09a3d20b-5871-47f4-9218-df119698e405@m4g2000yqf.googlegroups.com>
In-Reply-To <09a3d20b-5871-47f4-9218-df119698e405@m4g2000yqf.googlegroups.com>
Accept-Language en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
x-originating-ip [10.67.79.47]
Content-Transfer-Encoding quoted-printable
MIME-Version 1.0
X-DLP-FWD Yes
Content-Type text/plain; charset="us-ascii"
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.3400.1352329734.27098.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1352329734 news.xs4all.nl 6893 [2001:888:2000:d::a6]:57712
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:32912

Show key headers only | View raw


Anders wrote:
> 
> I've run into a Unicode error, and despite doing some googling, I
> can't figure out the right way to fix it. I have a Python 2.6 script
> that reads my Outlook 2010 task list. I'm able to read the tasks from
> Outlook and store them as a list of objects without a hitch.  But when
> I try to print the tasks' subjects, one of the tasks is generating an
> error:
> 
> 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)
> 
> (where task.subject  was previously assigned the value of
> task.Subject, aka the Subject property of an Outlook 2010 TaskItem)
> 
> From what I understand from reading online, the error is telling me
> that the subject line  contains an en dash and that Python is trying
> to convert to ascii and failing (as it should).
> 
> 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?
> 
> BTW, if there's a clear description of the best solution for this
> particular problem - i.e., where I want to ultimately display the
> results as HTML - please feel free to refer me to the link. I tried
> reading a number of docs on the web but still feel pretty lost.
> 

You can always encode in a non-ASCII codec. 
`print task.subject.encode(<encoding>)` where <encoding> is something that
supports the characters you want e.g. latin1. 

The list of built in codecs can be found:
http://docs.python.org/library/codecs.html#standard-encodings


~Ramit



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

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