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


Groups > comp.lang.python > #87161

Opaque error message on UTF-8 decode

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!bcyclone04.am1.xlned.com!bcyclone04.am1.xlned.com!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!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.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:error': 0.03; 'continuation': 0.07; 'explicit': 0.07; 'skip:u 30': 0.07; 'utf-8': 0.07; 'byte,': 0.16; 'character.': 0.16; 'codec': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:UTF': 0.16; 'surrogate': 0.16; 'index': 0.16; "python's": 0.19; '>>>': 0.22; 'to:name:python-list@python.org': 0.22; 'this?': 0.23; 'error': 0.23; 'byte': 0.24; 'tracker': 0.26; 'raise': 0.29; 'message-id:@mail.gmail.com': 0.30; '"",': 0.31; 'file': 0.32; '(most': 0.33; 'beginning': 0.33; 'could': 0.34; 'problem': 0.35; "can't": 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'sequence': 0.36; 'should': 0.36; 'to:addr:python-list': 0.38; 'issue': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'more': 0.64; 'worth': 0.66; 'invalid': 0.68; 'hassle?': 0.84; 'improvement,': 0.84; 'pike': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=L12Szrk2U2vw1vmHl1DU9ODtiR7etEw/21R2zSALF8Y=; b=GPIrj85Eg4uSkYaOtgUjSfgSJo+e3ZnnE9GWuCXPfu00nLx8qs2YeLxDgTJEnCQKLx H2wZzu/P/4oMuupASbQ8rFqhu2xlEoKvgmUKmih1nEFKJ/9Ejayvevr3i4wYHi5N9tWG gP0nzE1saVntsbgwTBd6jizJOkEGh4a2XWpnu9gim4/wfCmBuDKHoV1Ec4bo6guAh6fi /q0pT5uzULlY9urCZUEt2vVV/F6pBuA5bHwNuzMXLpWpMgbE0a0ElAm2sNfjGNL7ssS2 4AQ4/jM7J+UrSpEwgcziefE1zewhQdUWpLrsaFt+Eb3ZoZ0ZQLdwQehsyYd52ExX5rIy dEAg==
MIME-Version 1.0
X-Received by 10.107.128.219 with SMTP id k88mr41688495ioi.27.1425849328025; Sun, 08 Mar 2015 14:15:28 -0700 (PDT)
Date Mon, 9 Mar 2015 08:15:27 +1100
Subject Opaque error message on UTF-8 decode
From Chris Angelico <rosuav@gmail.com>
To "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.19
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.176.1425849330.21433.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1425849330 news.xs4all.nl 2893 [2001:888:2000:d::a6]:33140
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 3699
X-Received-Body-CRC 2422953406
Xref csiph.com comp.lang.python:87161

Show key headers only | View raw


>>> b"\xed\xb4\x80".decode()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xed in position
0: invalid continuation byte

But 0xED is not a continuation byte, it's a start byte. And it's a
perfectly valid one:

>>> b"\xed\x9f\xbf".decode()
'\ud7ff'

Pike is more explicit about what the problem is:

> utf8_to_string("\xed\xb4\x80");
UTF-8 sequence beginning with 0xed 0xb4 at index 0 would decode to a
UTF-16 surrogate character.

Is this something where Python's error message could do with
improvement, or is it not worth the hassle? Should I raise a tracker
issue about this?

ChrisA

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


Thread

Opaque error message on UTF-8 decode Chris Angelico <rosuav@gmail.com> - 2015-03-09 08:15 +1100

csiph-web