diff -r cf70f030a744 Lib/SimpleHTTPServer.py --- a/Lib/SimpleHTTPServer.py Wed Jun 18 23:07:46 2014 -0400 +++ b/Lib/SimpleHTTPServer.py Mon Jun 23 21:56:53 2014 +0300 @@ -138,8 +138,12 @@ length = f.tell() f.seek(0) self.send_response(200) - encoding = sys.getfilesystemencoding() - self.send_header("Content-type", "text/html; charset=%s" % encoding) + try: + encoding = sys.getfilesystemencoding() + except AttributeError: + self.send_header("Content-type", "text/html") + else: + self.send_header("Content-type", "text/html; charset=%s" % encoding) self.send_header("Content-Length", str(length)) self.end_headers() return f diff -r cf70f030a744 Lib/httplib.py --- a/Lib/httplib.py Wed Jun 18 23:07:46 2014 -0400 +++ b/Lib/httplib.py Mon Jun 23 21:56:53 2014 +0300 @@ -83,6 +83,12 @@ except ImportError: from StringIO import StringIO +try: + unicode + _have_unicode = True +except NameError: + _have_unicode = False + __all__ = ["HTTP", "HTTPResponse", "HTTPConnection", "HTTPException", "NotConnected", "UnknownProtocol", "UnknownTransferEncoding", "UnimplementedFileMode", @@ -916,10 +922,13 @@ nil, netloc, nil, nil, nil = urlsplit(url) if netloc: - try: - netloc_enc = netloc.encode("ascii") - except UnicodeEncodeError: - netloc_enc = netloc.encode("idna") + if _have_unicode: + try: + netloc_enc = netloc.encode("ascii") + except UnicodeEncodeError: + netloc_enc = netloc.encode("idna") + else: + netloc_enc = netloc self.putheader('Host', netloc_enc) else: if self._tunnel_host: @@ -929,10 +938,13 @@ host = self.host port = self.port - try: - host_enc = host.encode("ascii") - except UnicodeEncodeError: - host_enc = host.encode("idna") + if _have_unicode: + try: + host_enc = host.encode("ascii") + except UnicodeEncodeError: + host_enc = host.encode("idna") + else: + host_enc = host # Wrap the IPv6 Host Header with [] (RFC 2732) if host_enc.find(':') >= 0: host_enc = "[" + host_enc + "]"