Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #95642
| Path | csiph.com!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.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; 'subject:Python': 0.05; 'line:': 0.07; 'cc:addr:python-list': 0.09; 'scripts': 0.09; 'subject:characters': 0.09; 'subject:script': 0.09; 'python': 0.10; 'wed,': 0.15; 'encoding': 0.15; 'explicitly': 0.15; 'subject: \n ': 0.15; '"use': 0.16; "'a')": 0.16; "'a',": 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'omitting': 0.16; 'subject:non': 0.16; 'subject:run': 0.16; 'wrote:': 0.16; 'string': 0.17; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'aug': 0.20; 'not,': 0.22; 'am,': 0.23; 'header:In-Reply-To:1': 0.24; 'least': 0.27; 'message- id:@mail.gmail.com': 0.27; "i'd": 0.31; 'run': 0.33; 'avoiding': 0.33; 'instead,': 0.33; 'file': 0.34; 'received:google.com': 0.35; 'text': 0.35; 'but': 0.36; 'should': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'means': 0.39; 'subject:-': 0.39; 'your': 0.60; 'default': 0.61; '26,': 0.72; 'chrisa': 0.84; 'to:none': 0.91 |
| 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:cc :content-type; bh=1Rr0WIB12oZmjodAOe/KfXtu9SLTeO4gsYwllC+DzWw=; b=vUwee7NeOfufAaR02m+UJLHUsbu6O7LMQivA6ZHljWTi39+vJQKqnahiC6d3M0YfnU eS0vGV0mtRcskVCF4+pMajc23iZYPpQsnR2EpY0Vn055HUq0Q6Inf02nquT2mMDZPIlJ ZUJAA2l2wKAWB/jCXlw4ItyH91OwKeEKnCPXuYnyWIDyYkqQ4qeTj1RVTZaH+r6s79vy TaX4Chs0Etfio39QG2iOjrqYBGIN7LPfDkU1VhwgLYNhspabo/nxNtGmcNJn5nrD4GTl weUlF5KSNXWYA70gCLSEDjE6H8RxTkBBPd+o7ZupBatm9oUn9kPDjdapmJ+CE4RUMSHZ Z70A== |
| MIME-Version | 1.0 |
| X-Received | by 10.107.134.146 with SMTP id q18mr10994473ioi.31.1440544570600; Tue, 25 Aug 2015 16:16:10 -0700 (PDT) |
| In-Reply-To | <c085c6af-31f6-480c-a9b4-90f46441fdd1@googlegroups.com> |
| References | <c085c6af-31f6-480c-a9b4-90f46441fdd1@googlegroups.com> |
| Date | Wed, 26 Aug 2015 09:16:10 +1000 |
| Subject | Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.35.1440544578.11709.python-list@python.org> (permalink) |
| Lines | 24 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1440544578 news.xs4all.nl 23735 [2001:888:2000:d::a6]:34056 |
| X-Complaints-To | abuse@xs4all.nl |
| X-Received-Bytes | 4072 |
| X-Received-Body-CRC | 1164268702 |
| Xref | csiph.com comp.lang.python:95642 |
Show key headers only | View raw
On Wed, Aug 26, 2015 at 7:19 AM, RAH <rene.heymans@gmail.com> wrote:
> rb = request_body.decode() # string
I'd recommend avoiding this operation in Python 2. As of Python 3,
omitting the encoding means "UTF-8", but in Python 2 it means "use the
default encoding", and that often causes problems in scripts that run
in various background environments. Instead, explicitly say what
encoding you're using:
rb = request_body.decode("UTF-8")
Conversely, if you're using Python 3 for this, the default encoding is
coming from this line:
> h = open('logdict', 'a')
Again, if you want this to be a text file with a specific encoding, say so:
h = open('logdict', 'a', encoding='UTF-8')
Give that a try and see if your problems disappear. If not, this
should at least poke them with a pointy stick.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
file.write() of non-ASCII characters differs in Interpreted Python than in script run RAH <rene.heymans@gmail.com> - 2015-08-25 14:19 -0700
Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run Chris Kaynor <ckaynor@zindagigames.com> - 2015-08-25 14:28 -0700
Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run RAH <rene.heymans@gmail.com> - 2015-08-26 02:12 -0700
Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run Chris Angelico <rosuav@gmail.com> - 2015-08-26 19:24 +1000
Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run RAH <rene.heymans@gmail.com> - 2015-08-26 07:24 -0700
Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run Chris Angelico <rosuav@gmail.com> - 2015-08-26 09:16 +1000
Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run RAH <rene.heymans@gmail.com> - 2015-08-26 07:18 -0700
Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run dieter <dieter@handshake.de> - 2015-08-26 07:51 +0200
Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run RAH <rene.heymans@gmail.com> - 2015-08-26 07:20 -0700
Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run Pete Dowdell <contact@stridebird.com> - 2015-08-26 14:09 +0700
Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run RAH <rene.heymans@gmail.com> - 2015-08-26 07:22 -0700
Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run RAH <rene.heymans@gmail.com> - 2015-08-26 08:02 -0700
Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run Chris Angelico <rosuav@gmail.com> - 2015-08-27 01:57 +1000
Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run RAH <rene.heymans@gmail.com> - 2015-08-26 12:23 -0700
Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run Chris Angelico <rosuav@gmail.com> - 2015-08-27 09:15 +1000
Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run Marko Rauhamaa <marko@pacujo.net> - 2015-08-27 08:59 +0300
Re: file.write() of non-ASCII characters differs in Interpreted Python than in script run RAH <rene.heymans@gmail.com> - 2015-08-27 07:01 -0700
csiph-web