Created
April 22, 2018 10:48
-
-
Save de1o/ed01a4621f5429b36aedd5f391e97eb0 to your computer and use it in GitHub Desktop.
add default timeout time for requests
This file contains 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 requests | |
def _hook_requests(): | |
try: | |
from requests.sessions import Session | |
except ImportError: | |
return | |
real_send = Session.send | |
def send(self, request, *args, **kwargs): | |
if not kwargs.get('timeout'): | |
kwargs['timeout'] = 3 | |
return real_send(self, request, *args, **kwargs) | |
Session.send = send | |
_hook_requests() | |
r = requests.get("http://localhost:5002/") | |
print(r.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment