Skip to content

cannot import name 'sanitizer' #277

Closed

Description

@erikzenker

I want install the django cms which uses the sanitizer of the html5lib,
but I get the error shown above in the title.

when I just import the sanitizer from html5lib:

from html5lib import sanitizer

I get the following error:

Traceback (most recent call last):
  File "test.py", line 1, in <module>
    from html5lib import sanitizer
ImportError: cannot import name 'sanitizer'

I installed html5lib from pip:

pip install html5lib

Is the sanitizer module not available anymore ?

Activity

  1. stefanfoulis commented on Jul 15, 2016

    @stefanfoulis

    @erikzenker It looks like it has been removed (or moved). Quickfix is to use a slightly older version of the package where sanitizer is still there:

    pip install html5lib<0.99999999
    

    ot: what is it with those weird version numbers anyway? You know you could also make it 0.10 .

  2. gsnedders commented on Jul 15, 2016

    @gsnedders
    Member

    That's #72 and #110. The sanitizer now exists only as a filter for the treewalkers, rather than something touching the tokenizer in odd ways that was likely broken.

    Our state of terrible documentation probably doesn't help here, and the changelog entry is rather useless in hindsight. The common-case is something like:

    from html5lib import parse, serialize
    
    def clean(s):
        d = parse(s)
        return serialize(s, sanitize=True)
    

    (0.10 is less than 0.9999999, so no, that option's long gone.)

  3. macolo commented on Jul 18, 2016

    @macolo

    You could make it 1.0 though. Counting the 9s makes me dizzy.

  4. DanielTate commented on Jan 30, 2017

    @DanielTate

    This is still not working.... Are there any real solutions to this?

  5. vhquang commented on Mar 15, 2023

    @vhquang

    As a2917e9, sanitizer is moved into filters. So to import (as of version 1.1), you would do:

    from html5lib.filters import sanitizer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions