3

In a Python script I use the "Requests" library with HTTP basic authentication and a custom CA certificate to trust like this:

import requests    
response = requests.get(base_url, auth=(username, password), verify=ssl_ca_file)

All requests I need to make have to use these parameters. Is there a "Python" way to set these as default for all requests?

1
  • requests has extensive documentation on the Session class. Use that. Commented Nov 21, 2015 at 19:43

1 Answer 1

5

Use Session(). Documentation states:

The Session object allows you to persist certain parameters across requests.

import requests

s = requests.Session()
s.auth = (username, password)
s.verify = ssl_ca_file

s.get(base_url)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.