httpwatcher icon indicating copy to clipboard operation
httpwatcher copied to clipboard

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

Open iwsfutcmd opened this issue 1 year ago • 8 comments

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.

iwsfutcmd avatar Apr 27 '23 18:04 iwsfutcmd

issue is in Tornado

Alex-CodeLab avatar May 05 '23 11:05 Alex-CodeLab

how do i solve this?

jionnyMagiah avatar Jun 11 '23 09:06 jionnyMagiah

@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

Alex-CodeLab avatar Jun 12 '23 10:06 Alex-CodeLab

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

jionnyMagiah avatar Jun 13 '23 08:06 jionnyMagiah

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)

Alex-CodeLab avatar Jun 13 '23 09:06 Alex-CodeLab

  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

jionnyMagiah avatar Jun 13 '23 09:06 jionnyMagiah

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

ewpratten avatar Oct 21 '23 17:10 ewpratten

~~Just updating tornado solves the issue for me~~

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

arogozhnikov avatar Jan 04 '24 05:01 arogozhnikov