Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'HTMLParser' object has no attribute 'unescape' #102

Open
eyalroz opened this issue Apr 10, 2022 · 4 comments
Open

AttributeError: 'HTMLParser' object has no attribute 'unescape' #102

eyalroz opened this issue Apr 10, 2022 · 4 comments

Comments

@eyalroz
Copy link

eyalroz commented Apr 10, 2022

I'm trying to use mdv on an old(ish) distribution, with Python 2.7.5 . When it runs, I get:

Traceback (most recent call last):
  File "/home/lh156516/.local/bin/mdv", line 33, in <module>
    sys.exit(load_entry_point('mdv==1.7.4', 'console_scripts', 'mdv')())
  File "/home/lh156516/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 1657, in run
    print(main(**kw) if PY3 else str(main(**kw)))
  File "/home/lh156516/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 1375, in main
    the_html = MD.convert(md)
  File "/usr/local/lib/python3.9/site-packages/markdown/core.py", line 268, in convert
    newRoot = treeprocessor.run(root)
  File "/home/lh156516/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 1150, in run
    formatter(doc, out)
  File "/home/lh156516/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 1145, in formatter
    formatter(c, out, hir + 1, parent=el)
  File "/home/lh156516/.local/lib/python3.9/site-packages/mdv/markdownviewer.py", line 970, in formatter
    t = html_parser.unescape(t)
AttributeError: 'HTMLParser' object has no attribute 'unescape'

If you don't support this Python version, the pip install should fail, or the script should say so. If you do support this version of python - then this is a bug.

@austinthresher
Copy link

This is an issue with Python 3.9; if you read the trace, you can see it right in the path. HTMLParser has changes in 3.9 that break mdv. If you're on Ubuntu, chances are the system installation of Python 3 is a little bit older, and should still work. Here's how I fixed this:
cat $(which mdv) will display the script that launches mdv. Take note of the first line, which indicates the path to the version of Python it's running in. If it already says #!/usr/bin/python3, then this fix won't work for you. If it says something else, it's not using your system Python but one that is installed somewhere else. which python3 should give you the same path. To fix this, we want to remove mdv from this version of Python and install it as a package for your system Python instead. If the two Python paths we saw matched, go ahead and remove mdv with python3 -m pip uninstall mdv.
Now, we want to install mdv to our system Python 3. Make sure you have the correct packages installed:
sudo apt-get install python3 python3-pip
Finally, we can install mdv:
/usr/bin/python3 -m pip install mdv
You'll probably need to start a new terminal session to see the change, but now if you do cat $(which mdv) it should show /usr/bin/python3 as the executable.

@eyalroz
Copy link
Author

eyalroz commented Apr 15, 2022

Here's how I fixed this:

You're suggesting that users should do something. I'm claiming that you should do something. If you require Python 3.9, then, when starting up - check the Python version, and if it's earlier, fail informatively.

Also, I'm stuck on an old distribution and can't play with the Python installation.

@dhondta
Copy link
Contributor

dhondta commented Sep 1, 2022

@austinthresher Wasn't this issue fixed with this commit ?
Moreover, this issue is a duplicate of #97 ...

@ehaupt
Copy link

ehaupt commented Oct 14, 2022

@austinthresher: this commit solves the issue. Any chance you could tag a new release? It's been a while since the last release 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants