Stacktrace for UserWarning

Viewed 947

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:

  • This is a warning from a production system. I don't want to change the source.
  • The next time a warning like this occurs, I would like to see the stacktrace immediately

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.

2 Answers
Related