5 examples of 'python requests session' in Python

Every line of 'python requests session' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
149def session(verify=None, force_curl=False):
150 """
151 Return either a Requests or a Curl session object.
152 """
153 if not force_curl and hasattr(httplib, "HTTPSConnection"):
154 sess = requests.Session()
155 sess.verify = verify
156 return sess
157 # try curl
158 return CurlSession(verify=verify)
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

22def session(proxies,headers,cookie):
23 r=requests.Session()
24 r.proxies=proxies
25 r.headers=headers
26 r.cookies.update(json.loads(cookie))
27 return r
31def get_requests(config):
32 """Return a configured Requests client.
33
34 NOTE: this is a convenience function only to reduce boiler plate.
35
36 Inputs:
37 config: k8s.configuration.Config instance
38 Typically you pass it whatever `k8s.utils.load_config()` returns.
39
40 Returns:
41 Requests session instance.
42 """
43 sess = requests.Session()
44 sess.verify = config.ssl_ca_cert
45 return sess
22def get_requests_session(proxy_config):
23 """This method was pulled from
24 https://github.com/mopidy/mopidy-spotify/blob/master/mopidy_spotify/utils.py
25 The possibility for proxy configuration was dropped and a static user agent is used
26 in order to remove the dependency to mopdiy."""
27 full_user_agent = "Mopidy-Spotify/4.0.1 Mopidy/3.0.2 CPython/3.7.5"
28
29 session = requests.Session()
30 session.headers.update({"user-agent": full_user_agent})
31
32 return session
18def get_session():
19 adapter = CacheControlAdapter(
20 DictCache(), cache_etags=True, serializer=None, heuristic=None
21 )
22 sess = requests.Session()
23 sess.mount("http://", adapter)
24 sess.mount("https://", adapter)
25
26 sess.cache_controller = adapter.controller
27 return sess

Related snippets