When trying to use BS4 I got the following error:
Traceback (most recent call last):
File "script.py", line 16, in <module>
mycall()
File "/home/user/mycode.py", line 63, in downloadDataset
soup = BeautifulSoup(r, "html5lib")
File "/home/user/.local/lib/python3.8/site-packages/bs4/__init__.py", line 348, in __init__
self._feed()
File "/home/user/.local/lib/python3.8/site-packages/bs4/__init__.py", line 434, in _feed
self.builder.feed(self.markup)
File "/home/user/.local/lib/python3.8/site-packages/bs4/builder/_html5lib.py", line 87, in feed
doc = parser.parse(markup, **extra_kwargs)
File "/usr/lib/python3/dist-packages/html5lib/html5parser.py", line 223, in parse
self._parse(stream, innerHTML=False, encoding=encoding,
File "/usr/lib/python3/dist-packages/html5lib/html5parser.py", line 93, in _parse
self.mainLoop()
File "/usr/lib/python3/dist-packages/html5lib/html5parser.py", line 187, in mainLoop
new_token = phase.processStartTag(new_token)
File "/usr/lib/python3/dist-packages/html5lib/html5parser.py", line 468, in processStartTag
return self.startTagHandler[token["name"]](token)
File "/usr/lib/python3/dist-packages/html5lib/html5parser.py", line 1258, in startTagMath
self.parser.adjustForeignAttributes(token)
File "/usr/lib/python3/dist-packages/html5lib/html5parser.py", line 339, in adjustForeignAttributes
for originalName in token["data"].keys():
RuntimeError: dictionary keys changed during iterationI checked the function "adjustForeignAttributes" and it indeed changes dictionary keys while iterating over it. I've tried to replicate this in a separated snippet and it throws another error, so I guess doing this is problematic.
I'm a bit surprised because I was parsing something similar (maybe even the same) and I did not get this error before. Also, I haven't changed my python version for a while (3.8.6). By disabling this function (commenting line 1259) it performs the desired behavior. Questions:
1) Is calling this function necessary? What does it do in practice?
2) Why do I get this error? Why changing the dictionary keys is being done?
Thanks