﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
23398	Attempting to access a manage.py runserver instance over HTTPS raises UnicodeDecodeError	Robert Rollins	Flavio Curella	"I realize that the runserver command is not designed to function over HTTPS, but it would be much more useful for users who ''don't'' realize that (like the 1-hour-ago version of me) if the exception that Django throws from HTTPS access attempts was not an apparently random UnicodeDecodeError from the logging system.

Right now, with Django 1.6.5, attempting to access any URL on a runserver instance over HTTPS will result in this traceback being shown multiple times in the server console:

{{{
Traceback (most recent call last):
  File ""/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServer.py"", line 560, in process_request_thread
    self.finish_request(request, client_address)
  File ""/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServer.py"", line 322, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File ""/srv/ads/django/tmtpds/ve/lib/python2.6/site-packages/django/core/servers/basehttp.py"", line 126, in __init__
    super(WSGIRequestHandler, self).__init__(*args, **kwargs)
  File ""/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/SocketServer.py"", line 617, in __init__
    self.handle()
  File ""/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/wsgiref/simple_server.py"", line 131, in handle
    if not self.parse_request(): # An error code has been sent, just exit
  File ""/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/BaseHTTPServer.py"", line 289, in parse_request
    self.send_error(400, ""Bad request syntax (%r)"" % requestline)
  File ""/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/BaseHTTPServer.py"", line 357, in send_error
    self.send_response(code, message)
  File ""/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/BaseHTTPServer.py"", line 374, in send_response
    self.log_request(code)
  File ""/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/BaseHTTPServer.py"", line 411, in log_request
    self.requestline, str(code), str(size))
  File ""/srv/ads/django/tmtpds/ve/lib/python2.6/site-packages/django/core/servers/basehttp.py"", line 138, in log_message
    msg = ""[%s] %s\n"" % (self.log_date_time_string(), format % args)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xcd in position 12: ordinal not in range(128)
}}}

It's not always exactly the same byte having problems, but it's always line 138 in `django/core/servers/basehttp.py`. The server is attempting to log an ""HTTP 400: Bad request syntax"" error, but it's failing to decode the URL from what it seems to think is unicode to ascii. From my googling, it appears that this is happening because the browser encrypts the URL, and runserver is getting that encrypted URL and having no idea what to do with it.

It would be really helpful for uniformed users like my past self if this error were reported as ""You can't use HTTPS with runserver"" rather than what we're currently getting."	New feature	closed	HTTP handling	1.6	Normal	fixed			Accepted	1	0	0	1	0	0
