Last active
May 30, 2018 11:58
-
-
Save fawkesley/7a83bac60707a618cd896cdda8823c36 to your computer and use it in GitHub Desktop.
Wrapper for python requests providing session and user agent
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 requests | |
class RequestsWrapper(): | |
def __init__(self, user_agent): | |
self._session = requests.Session() | |
self._user_agent = user_agent | |
def get(self, *args, **kwargs): | |
headers = requests.structures.CaseInsensitiveDict( | |
kwargs.get('headers', {}) | |
) | |
if 'user-agent' not in headers: | |
headers['user-agent'] = self._user_agent | |
timeout = kwargs.pop('timeout', 10) | |
return self._session.get(headers=headers, timeout=timeout, *args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Then in your code: