Created
September 20, 2017 09:40
-
-
Save rrader/3d2edb0a362910b78fe640042923fc45 to your computer and use it in GitHub Desktop.
Test open files on requests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import psutil | |
| import requests | |
| def open_files(): | |
| proc = psutil.Process() | |
| return proc.open_files() | |
| print 'on start:', open_files() | |
| f = open('/etc/hosts', 'r') | |
| print 'hosts file opened:', open_files() | |
| f.close() | |
| print 'hosts file closed:', open_files() | |
| url = 'http://httpbin.org/post' | |
| multiple_files = [ | |
| ('images', ('hosts', open('/etc/hosts', 'rb'), 'plain/text')), | |
| ('images', ('resolv.conf', open('/etc/resolv.conf', 'rb'), 'plain/text'))] | |
| r = requests.post(url, files=multiple_files) | |
| print 'after request:', open_files() |
Author
rrader
commented
Sep 20, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment