Accessing stderr after running python script via sh module
I am running a Python script through the sh module and it crashes at runtime. After a crash, it gives me a read of the first few lines of stderr, but it tells me that there are more errors and that I should see e.stderr, but I cannot figure out how to do this because I donβt understand what e is. How can I access the rest of my stderr file? Thank.
EDIT: Here is the error:
STDERR:
mydir/test.py:22: UserWarning: gzip transfer encoding is experimental!
br.set_handle_gzip(True)
Traceback (most recent call last):
File "mydir/test.py", line 142, in <module>
run(sys.argv[1]);
File "mydir/test.py", line 13, in run
scrape(browser,folderName);
File "mydir/test.py", line 46, in scrape
processResponse(browser,folderName,1);
File "mydir/test.py", line 121, in processResponse
urllib.urlencode(data));
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/mechanize-0.2.6.dev_20130122-py2.7.egg/mechanize/_mechanize.py", line 203, in open
return self._mech_open(url, data, timeout=timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-pac... (4278 more, please see e.stderr)
source to share
The e.stderr message comes from the module sh
.
( https://github.com/amoffat/sh/blob/30bd191a4f966bcf82c5666c56aeb1060d035920/sh.py#L148 )
I wrote a simple program error.py
that just writes a lot to stderr and then exits with a non-zero return code. To get rid of the message, just use a try / except block:
import sh
cmd = sh.Command("./error.py")
try:
c = cmd()
except sh.ErrorReturnCode, e:
print e.stderr
source to share
Check out this answer: What does the br.set_handle_gzip tag mechanic do?
We hope that the number of errors will be less than 1.
source to share