[Feature] Add SSL Certificate Context And Setting For Async/Sync HTTP Requests #6976
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why?:
The Requests library accepts an environment variable,
REQUESTS_CA_BUNDLE
, and AIOHTTP does not. This creates inconsistencies between synchronous and async HTTP requests. Furthermore, defining this variable limits the Requests library to that particular file. If you want to use a self-signed certificate for only some things, it is not straightforward.This solution combines the specified certificate with the
certifi
defaults.What?:
system_settings.json
to accept extras.http
as a nested dictionary.make_request
amake_request
amake_requests
uvicorn.run
by storing them as a dictionary to:system_settings.python_settings.uvicorn
Impact:
REQUESTS_CA_BUNDLE
, ports directly to the async requests.system_settings.json
instead of environment variables.cafile
is an equivalent toREQUESTS_CA_BUNDLE
, when pointing to a file."verify_ssl": false
, SSL certificate verification is disabled within all OpenBB functions."python_settings["uvicorn"]"
dictionary are passed directly touvicorn.run
when launching the API as:python -m openbb_core.api.rest_api
openbb-api
These items, in
system_settings.json
, will take precedence over environment variables:Note: Keyword arguments added to the command line from
openbb-api
take precedence over thesystem_settings.json
file.Testing Done:
.crt
file as shown above.requests
andopenbb_core.provider.utils.helpers.make_request
requests.get
should fail whilemake_request
succeeds.null
and addREQUESTS_CA_BUNDLE='/full/path/to/certificate/localhost.crt'
to the.env
file.requests.get
andmake_request
should succeed.requests.get("https://google.com")
will fail,make_request
should succeed.With the environment variable defined, and not
system_settings.json
, the same A/B can be applied toyfinance.download()
vs. `obb.equity.price.historical(provider="yfinance")This fails because yFinance is only verifying against the self-signed certificate for
localhost
.openbb_yfinance.utils.helpers.yf_download
applies the environment configuration for the duration of the request.