You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
session.merge_environment_settings is called in session.request and not in session.send which means if users want to build their own prepared requests (see example below), the correct certificates file will not be used unless explicitly passed to send.
I believe these environment settings should be updated in session.send instead.
Reproduction Steps
importosimportrequests# Set CA certificates file to custom local fileos.environ["REQUESTS_CA_BUNDLE"] ="/etc/ssl/certs/ca-certificates.crt"# Create request objectreq=requests.Request(
method="GET", # any methodurl="https://www.example_site.mydomain.com/path"# any url for which the default cert file does not have a cert for
)
withrequests.Session() ass:
respA=s.request( # Success: will use CA certificates from REQUESTS_CA_BUNDLEmethod=req.method,
url=req.url
)
assertrespA.status_code==200withrequests.Session() ass:
respB=s.send( # Success: will use CA certificates from REQUESTS_CA_BUNDLE if explicitly specifiedrequest=req.prepare(), verify=os.environ["REQUESTS_CA_BUNDLE"]
)
assertrespB.status_code==200withrequests.Session() ass:
respC=s.send( # Error: Will try to use default CA certificates instead of those specified by REQUESTS_CA_BUNDLErequest=req.prepare()
)
assertrespC.status_code==200
Expected Result
No output
Actual Result
requests.exceptions.SSLError: HTTPSConnectionPool(host='https://www.example_site.mydomain.com/path', port=443): Max retries exceeded with url: /path (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))
I can confirm I'm seeing this behavior when using prepared requests and sessions.send(), being forced to set session.verify = os.environ['REQUESTS_CA_BUNDLE'] before send().
Bug in requests.sessions.py:
requests/src/requests/sessions.py
Lines 579 to 589 in b8be93a
session.merge_environment_settings is called in session.request and not in session.send which means if users want to build their own prepared requests (see example below), the correct certificates file will not be used unless explicitly passed to send.
I believe these environment settings should be updated in session.send instead.
Reproduction Steps
Expected Result
No output
Actual Result
System Information
The text was updated successfully, but these errors were encountered: