1 2 3 4 5 6 7 8 9 10 11 12 | import os, tempfile, subprocess
URL_OPENER = 'xdg-open'
def open_response_content(response):
""" Saves a response's content to a temporary file and opens it in a
browser. """
temp_file = tempfile.NamedTemporaryFile(delete=False)
temp_file.write(response.content)
dev_null = open(os.devnull, 'w')
kwargs = {'stdout': dev_null, 'stderr': dev_null}
subprocess.Popen([URL_OPENER, temp_file.name], **kwargs)
|
More like this
- Load response.content in browser (for debugging) by tin_nqn 1 year ago
- Decorator and context manager to override settings by jezdez 2 years ago
- A smart trace() command by aparajita 3 years, 11 months ago
- Forcing unit test runner to abort after failed test by simonbun 6 years ago
- "Zoom in" on rendered HTML that the test client returns by peterbe 4 years, 1 month ago
Comments