[New-bugs-announce] [issue22165] Empty response from http.server when directory listing contains invalid unicode

Josh Lee report at bugs.python.org
Thu Aug 7 17:06:33 CEST 2014


New submission from Josh Lee:

While SimpleHTTPServer from Python2 would happily spit out whatever bytes were in the directory listing, Python3's http.server logs an error and closes the connection without responding to the HTTP request.

$ mkdir $'\xff'
$ ls
\377/
$ python3 -m http.server 
Serving HTTP on 0.0.0.0 port 8000 ...
----------------------------------------
Exception happened during processing of request from ('74.125.59.145', 19648)
Traceback (most recent call last):
  File "/home/josh/local/lib/python3.5/socketserver.py", line 321, in _handle_request_noblock
    self.process_request(request, client_address)
  File "/home/josh/local/lib/python3.5/socketserver.py", line 347, in process_request
    self.finish_request(request, client_address)
  File "/home/josh/local/lib/python3.5/socketserver.py", line 360, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/home/josh/local/lib/python3.5/socketserver.py", line 681, in __init__
    self.handle()
  File "/home/josh/local/lib/python3.5/http/server.py", line 398, in handle
    self.handle_one_request()
  File "/home/josh/local/lib/python3.5/http/server.py", line 386, in handle_one_request
    method()
  File "/home/josh/local/lib/python3.5/http/server.py", line 677, in do_GET
    f = self.send_head()
  File "/home/josh/local/lib/python3.5/http/server.py", line 716, in send_head
    return self.list_directory(path)
  File "/home/josh/local/lib/python3.5/http/server.py", line 772, in list_directory
    % (urllib.parse.quote(linkname), html.escape(displayname)))
  File "/home/josh/local/lib/python3.5/urllib/parse.py", line 688, in quote
    string = string.encode(encoding, errors)
UnicodeEncodeError: 'utf-8' codec can't encode character '\udcff' in position 0: surrogates not allowed
----------------------------------------

----------
components: Library (Lib)
messages: 225016
nosy: durin42, jleedev
priority: normal
severity: normal
status: open
title: Empty response from http.server when directory listing contains invalid unicode
versions: Python 3.5

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22165>
_______________________________________


More information about the New-bugs-announce mailing list