UserWarning Import Error

194 views
Skip to first unread message

jlo

unread,
Aug 27, 2023, 5:00:25 PM8/27/23
to beautifulsoup
Hello,

I'm trying to suppress parsing error like the following:

/Users/REDACTED/Library/Python/3.9/lib/python/site-packages/bs4/builder/_htmlparser.py:102: UserWarning: expected name token at '<![��H�\x05�"��V��\x06u��@' time:  0:52:19.475862                        warnings.warn(msg)

I found this solution on Stackexchange that sounded perfect, but it appears that UserWarning no longer exists:

>>> from bs4 import UserWarning
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'UserWarning' from 'bs4' (/Users/REDACTED/Library/Python/3.9/lib/python/site-packages/bs4/__init__.py)

Can UserWarning still be imported?

Thanks.

leonardr

unread,
Aug 27, 2023, 8:36:26 PM8/27/23
to beautifulsoup
UserWarning is a Python built-in exception and doesn't need to be imported at all. You can just write UserWarning.

>>> UserWarning
<class 'UserWarning'>


It's possible that in earlier versions UserWarning was present in bs4/__init__.py, and it would have been  possible to import UserWarning from that module, but I can't see any version where that is the case, and if so, it would have only worked by accident.

Leonard

jlo

unread,
Aug 28, 2023, 3:15:54 PM8/28/23
to beautifulsoup
This is perfect. Thank you!
Reply all
Reply to author
Forward
0 new messages