d:\Repo\hg>hg serve ** unknown exception encountered, please report by visiting ** http://mercurial.selenic.com/wiki/BugTracker ** Python 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)] ** Mercurial Distributed SCM (version 2.9) ** Extensions loaded: gpg Traceback (most recent call last): File "hg", line 42, in <module> File "mercurial\dispatch.pyo", line 28, in run File "mercurial\dispatch.pyo", line 69, in dispatch File "mercurial\dispatch.pyo", line 134, in _runcatch File "mercurial\dispatch.pyo", line 806, in _dispatch File "mercurial\dispatch.pyo", line 586, in runcommand File "mercurial\dispatch.pyo", line 897, in _runcommand File "mercurial\dispatch.pyo", line 868, in checkargs File "mercurial\dispatch.pyo", line 803, in <lambda> File "mercurial\util.pyo", line 511, in check File "mercurial\commands.pyo", line 5204, in serve File "mercurial\cmdutil.pyo", line 514, in service File "mercurial\commands.pyo", line 5214, in init File "mercurial\hgweb\server.pyo", line 325, in create_server File "mimetypes.pyo", line 358, in init File "mimetypes.pyo", line 258, in read_windows_registry File "mimetypes.pyo", line 249, in enum_types UnicodeDecodeError: 'ascii' codec can't decode byte 0xd8 in position 0: ordinal not in range(128)
We've seen this before but I'm not marking it a duplicate. We've got a workaround for everything except hg serve / hgweb here: http://bz.selenic.com/show_bug.cgi?id=3624
Proposed fix: diff -r 4d5322dec91f mercurial/hgweb/server.py --- a/mercurial/hgweb/server.py Sun Nov 17 20:16:14 2013 +0100 +++ b/mercurial/hgweb/server.py Wed Feb 05 16:11:16 2014 -0600 @@ -322,7 +322,19 @@ cls = MercurialHTTPServer # ugly hack due to python issue5853 (for threaded use) - import mimetypes; mimetypes.init() + try: + import mimetypes + mimetypes.init() + except UnicodeDecodeError: + # Python 2.x's mimetypes module attempts to decode strings + # from Windows' ANSI APIs as ascii (fail), then re-encode them + # as ascii (clown fail), because the default Python Unicode + # codec is hardcoded as ascii. + reload(sys) + oldenc = sys.getdefaultencoding() + sys.setdefaultencoding("latin1") # or any full 8-bit encoding + mimetypes.init() + sys.setdefaultencoding(oldenc) address = ui.config('web', 'address', '') port = util.getport(ui.config('web', 'port', 8000))
Fixed by http://selenic.com/repo/hg/rev/6863d42eb59a Matt Mackall <mpm@selenic.com> hgweb: hack around mimetypes encoding thinko (issue4160) A correct patch for this has existed in Python's BTS for 3 years (http://bugs.python.org/issue9291), so waiting for it to be fixed upstream is probably not a viable strategy. Instead, we add this horrible hack to workaround the issue in existing copies of Python 2.4-2.7. (please test the fix)
I've replaced the server.pyo file with the updated server.py and got following traceback: ** unknown exception encountered, please report by visiting ** http://mercurial.selenic.com/wiki/BugTracker ** Python 2.7.6 (default, Nov 10 2013, 19:24:24) [MSC v.1500 64 bit (AMD64)] ** Mercurial Distributed SCM (version 2.9) ** Extensions loaded: Traceback (most recent call last): File "hg", line 42, in <module> File "mercurial\dispatch.pyo", line 28, in run File "mercurial\dispatch.pyo", line 69, in dispatch File "mercurial\dispatch.pyo", line 134, in _runcatch File "mercurial\dispatch.pyo", line 806, in _dispatch File "mercurial\dispatch.pyo", line 586, in runcommand File "mercurial\dispatch.pyo", line 897, in _runcommand File "mercurial\dispatch.pyo", line 868, in checkargs File "mercurial\dispatch.pyo", line 803, in <lambda> File "mercurial\util.pyo", line 511, in check File "mercurial\commands.pyo", line 5204, in serve File "mercurial\cmdutil.pyo", line 514, in service File "mercurial\commands.pyo", line 5214, in init File "C:\Program Files\TortoiseHg\library.zip\mercurial\hgweb\server.py", line 334, in create_server TypeError: reload() argument must be module
That should be fixed by http://selenic.com/repo/hg/rev/ca970d6acedb .
Yes, now it works. Thank you!