thanethomson / httpwatcher

Python-based HTTP server for static files with live reload
MIT License
20 stars 10 forks source link

No longer works on Python >= 3.10 due to `MutableMapping` moving #12

Open iwsfutcmd opened 1 year ago

iwsfutcmd commented 1 year ago

When attempting to run httpwatcher on Python >=3.10, you get the following error:

AttributeError: module 'collections' has no attribute 'MutableMapping'

This is because in Python3.10, MutableMapping was moved from collections to collections.abc.

Alex-CodeLab commented 1 year ago

issue is in Tornado

jionnyMagiah commented 1 year ago

how do i solve this?

Alex-CodeLab commented 1 year ago

@giovann997 change the import

   from collections.abc import MutableMapping

or

if sys.version_info.major == 3 and sys.version_info.minor >= 10:

      from collections.abc import MutableMapping
  else:
      from collections import MutableMapping
jionnyMagiah commented 1 year ago

In which file? I've changed '/home/user/.local/lib/python3.11/site-packages/tornado/httputil.py', but it didn't worked

Alex-CodeLab commented 1 year ago

I don't know for sure, because it could be in a venv. I assume the error message tells you where it is?

And make sure it is used correctly, something like

 class HTTPHeaders(collections.MutableMapping)

or

    ....
    # from  collections.abc import MutableMapping
    from collections import MutableMapping
    class HTTPHeaders(MutableMapping)
jionnyMagiah commented 1 year ago
  File "/home/user/Documenti/GitHub/Thesis/serve.py", line 1, in <module>
    from httpwatcher import HttpWatcherServer
  File "/home/user/.local/lib/python3.11/site-packages/httpwatcher/__init__.py", line 4, i
n <module>                                                                                   from httpwatcher.server import *
  File "/home/user/.local/lib/python3.11/site-packages/httpwatcher/server.py", line 13, in
 <module>                                                                                    import tornado.web
  File "/home/user/.local/lib/python3.11/site-packages/tornado/web.py", line 86, in <modul
e>                                                                                           from tornado import httputil
  File "/home/user/.local/lib/python3.11/site-packages/tornado/httputil.py", line 111, in 
<module>                                                                                     class HTTPHeaders(collections.MutableMapping):
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'collections' has no attribute 'MutableMapping'

I tried adding from collections import MutableMapping before class HTTPHeaders(MutableMapping), but shows the same error

ewpratten commented 10 months ago

You can temporarily fix this by importing httpwatcher like this:

import collections.abc
collections.MutableMapping = collections.abc.MutableMapping
import httpwatcher

NOTE: The order is very important

arogozhnikov commented 8 months ago

Just updating tornado solves the issue for me

Actually, nvm, for some reason html is not auto-reloaded in browser