I see a warning like this in my logs:
py.warnings.__init__: WARNING .../bs4/__init__.py:219: UserWarning: "foo"
looks like a filename, not markup. You should probably open this file
and pass the filehandle into Beautiful Soup
This message does not help very much.
I would like to see the stacktrace where this happens.
Please don't look into the content of this warning. This question is not about Beautiful Soup :-)
An easy solution would be to modify the third party code (bs4/__init__.py
at line 219) and add something like this:
import traceback
logger.warn('Exc at ...\n%s' % ''.join(traceback.format_stack()))
But I would like to avoid this. Reasons:
Is there a flag or setting for python which I can change, to see not only one line, but the while stacktrace? I need the upper frames to debug this.
In this environment Python 2.7 gets used.
You would need to do the following:
python -c "import site; site._script()"
, see USER_SITE variable contentsPlace a file usercustomize.py
in that directory with the following code:
import traceback
import warnings
_old_warn = warnings.warn
def warn(*args, **kwargs):
tb = traceback.extract_stack()
_old_warn(*args, **kwargs)
print("".join(traceback.format_list(tb)[:-1]))
warnings.warn = warn
Credits to this answer for the code.
Run the code as usual. My test code:
import warnings
def f():
warnings.warn("foz")
f()
Before the procedure:
$ python test_warn.py
test_warn.py:4: UserWarning: foz
warnings.warn("foz")
After:
$ python test_warn.py
<USER_SITE_REDACTED>/usercustomize.py:6: UserWarning: foz
_old_warn(*args, **kwargs)
File "test_warn.py", line 6, in <module>
f()
File "test_warn.py", line 4, in f
warnings.warn("foz")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With