This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: http.server.BaseHTTPRequestHandler.parse_request (TypeError: decoding str is not supported)
Type: crash Stage:
Components: Versions: Python 3.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, recharti, serhiy.storchaka
Priority: normal Keywords:

Created on 2014-11-18 23:16 by recharti, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg231350 - (view) Author: Ryan Chartier (recharti) Date: 2014-11-18 23:16
While the parse_request is handling the requestline, it tries to force the string into iso-8859-1 using an unsupported syntax.

Line #274 in server.py

requestline = str(self.raw_requestline, 'iso-8859-1')

Obviously, python complains.

TypeError: decoding str is not supported

I'm running python 3.4.2 and the line is present in the 3.4.2 source I downloaded from the python.org today.

That is all.
msg231351 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2014-11-18 23:23
With the vanilla BaseHTTPRequestHandler, this shouldn't happen. self.raw_requestline is read from a socket file, which returns bytes, so they can be decoded using str(bytes, encoding).

Can you please check if there are any third-party packages involved that call/subclass the classes from http.server and introduce a bytes/str confusion?  They might not be correctly/completely ported to Python 3 in that case.

In any case, a full traceback will be helpful to help debug this.
msg231359 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-11-19 08:04
self.raw_requestline is read from self.rfile:

    self.raw_requestline = self.rfile.readline(65537)

self.rfile is either socket stream

    self.rfile = self.connection.makefile('rb', self.rbufsize)

or in-memory bytes stream

    self.rfile = BytesIO(self.packet)

In both cases it is binary stream and produces bytes. I don't see a bug in the stdlib, it can be a bug in user code which sets self.rfile or self.raw_requestline to invalid value.
History
Date User Action Args
2022-04-11 14:58:10adminsetgithub: 67088
2015-02-10 08:46:39serhiy.storchakasetstatus: pending -> closed
2014-11-19 08:11:22georg.brandlsetstatus: open -> pending
resolution: not a bug
2014-11-19 08:04:43serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg231359
2014-11-18 23:23:19georg.brandlsetnosy: + georg.brandl
messages: + msg231351
2014-11-18 23:16:37recharticreate