Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'benjamin': 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; 'message-----': 0.17; 'script.': 0.17; 'unicode': 0.17; 'thanks,': 0.18; 'windows': 0.19; 'file.': 0.20; 'parse': 0.22; 'wednesday,': 0.22; 'cc:2**0': 0.23; 'purposes': 0.23; '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; 'fine': 0.28; 'character': 0.29; "i'm": 0.29; 'code': 0.31; 'file': 0.32; 'skip:- 10': 0.32; 'print': 0.32; 'getting': 0.33; 'traceback': 0.33; 'that,': 0.34; "can't": 0.34; 'received:172.16': 0.34; 'whatever': 0.35; 'so,': 0.35; 'subject:?': 0.35; 'something': 0.35; 'received:org': 0.36; 'really': 0.36; 'subject:': 0.36; 'characters': 0.36; 'email addr:python.org': 0.36; 'should': 0.36; 'charset:us-ascii': 0.36; 'does': 0.37; 'sent:': 0.37; 'subject:: ': 0.38; 'from:': 0.38; 'page': 0.38; 'where': 0.40; 'skip:" 10': 0.40; 'your': 0.60; 'skip:u 10': 0.60; 'containing': 0.61; 'telling': 0.61; 'email name:python-list': 0.62; 'tasks.': 0.65; 'subject': 0.66; 'received:12': 0.81; '(standard': 0.84; 'oscar': 0.84; 'received:172.16.1': 0.91 From: Anders Schneiderman To: Oscar Benjamin Date: Thu, 8 Nov 2012 09:00:43 -0500 Subject: RE: Right solution to unicode error? Thread-Topic: Right solution to unicode error? Thread-Index: Ac29P3D3YMByhQx1Tk2Hp0ldsxNb5QAedn1A References: <09a3d20b-5871-47f4-9218-df119698e405@m4g2000yqf.googlegroups.com> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1352383315 news.xs4all.nl 6946 [2001:888:2000:d::a6]:43162 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32950 Thanks, Oscar and Ramit! This is exactly what I was looking for. Anders=20 > -----Original Message----- > From: Oscar Benjamin [mailto:oscar.j.benjamin@gmail.com] > Sent: Wednesday, November 07, 2012 6:27 PM > To: Anders Schneiderman > Cc: python-list@python.org > Subject: Re: Right solution to unicode error? >=20 > On 7 November 2012 22:17, Anders wrote: > > > > Traceback (most recent call last): > > File "outlook_tasks.py", line 66, in > > 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? >=20 > 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 strin= g in a > way that can be understood by your terminal. You can try using chcp to se= t > the code page to something that works with your script. >=20 > 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 whateve= r > encoding (probably utf-8) you use in the html file. If you really just wa= nt your > script to be able to print unicode characters then you need to use someth= ing > other than cmd.exe (such as IDLE). >=20 >=20 > Oscar