__init__() got an unexpected keyword argument '%s'
Package:
pip
7379
Exception Class:
TypeError
Raise code
"""
:arg alphabetical_attributes: Reorder attributes to be in alphabetical order.
Defaults to ``False``.
"""
unexpected_args = frozenset(kwargs) - frozenset(self.options)
if len(unexpected_args) > 0:
raise TypeError("__init__() got an unexpected keyword argument '%s'" % next(iter(unexpected_args)))
if 'quote_char' in kwargs:
self.use_best_quote_char = False
for attr in self.options:
setattr(self, attr, kwargs.get(attr, getattr(self, attr)))
self.errors = []
self.strict = False
Links to the raise (1)
https://github.com/pypa/pip/blob/48dc9f400d45682f244aae0db324fbda280266a5/src/pip/_vendor/html5lib/serializer.py#L216See also in the other packages (1)
(❌️ No answer)
pipenv/init-got-an-unexpected-keyword-ar
Ways to fix
This happens when html5lib.serializer.serialize gets unexpected argument.
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)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-4-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>
Add a possible fix
Please authorize to post fix