votes up 5

Invalid hash for (package) using archive (archive.name)

Package:
poetry
github stars 16152
Exception Class:
RuntimeError

Raise code

"sha256:"
                + FileDependency(
                    package.name,
                    Path(archive.path) if isinstance(archive, Link) else archive,
                ).hash()
            )
            if archive_hash not in {f["hash"] for f in package.files}:
                raise RuntimeError(
                    f"Invalid hash for {package} using archive {archive.name}"
                )

            self._hashes[package.name] = archive_hash

        return archive

    def _downloa
😲 Agile task management is now easier than calling a taxi. #Tracklify
🙏 Scream for help to Ukraine
Today, 25th May 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

Ways to fix

votes up 1 votes down

The valid optional parameters should be in the following list.

options = ("quote_attr_values", 
            "quote_char", 
            "use_best_quote_char",
            "omit_optional_tags", 
            "minimize_boolean_attributes",
            "use_trailing_solidus", 
            "space_before_trailing_solidus",
            "escape_lt_in_attrs", 
            "escape_rcdata", 
            "resolve_entities",
            "alphabetical_attributes", 
            "inject_meta_charset",
            "strip_whitespace", 
            "sanitize")

Any other parameter name causes this exception

Code to reproduce the exception:

from html5lib.html5parser import parse
from html5lib.serializer import serialize
token_stream = parse('<html><body><p>Hi!</p></body></html>')
serialize(token_stream, omit_optional_tag=False)

The error output:

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-2-0a6c1b2a6780> in <module>()  2 from html5lib.serializer import serialize  3 token_stream = parse('<html><body><p>Hi!</p></body></html>') ----> 4 serialize(token_stream, omit_optional_tag=False) 
/usr/local/lib/python3.7/dist-packages/html5lib/serializer.py in serialize(input, tree, encoding, **serializer_opts)  98 # XXX: Should we cache this?  99 walker = treewalkers.getTreeWalker(tree) --> 100 s = HTMLSerializer(**serializer_opts)  101 return s.render(walker(input), encoding)  102  
/usr/local/lib/python3.7/dist-packages/html5lib/serializer.py in __init__(self, **kwargs)  214 unexpected_args = frozenset(kwargs) - frozenset(self.options)  215 if len(unexpected_args) > 0: --> 216 raise TypeError("__init__() got an unexpected keyword argument '%s'" % next(iter(unexpected_args)))  217 if 'quote_char' in kwargs:  218 self.use_best_quote_char = False 
TypeError: __init__() got an unexpected keyword argument 'omit_optional_tag'

Fixed version of the code:

from html5lib.html5parser import parse
from html5lib.serializer import serialize
token_stream = parse('<html><body><p>Hi!</p></body></html>')
serialize(token_stream, omit_optional_tags=False)

'<html><head></head><body><p>Hi!</p></body></html>'

'

May 06, 2022 kellemnegasi answer
kellemnegasi 29.0k

Add a possible fix

Please authorize to post fix