reflex/reflex/utils/net.py
benedikt-bartscher 4a6c16e9dc
More env var cleanup (#4248)
* fix and test bug in config env loading

* streamline env var interpretation with @adhami3310

* improve error messages, fix invalid value for TELEMETRY_ENABLED

* just a small hint

* ruffing

* fix typo from review

* refactor - ruff broke the imports..

* cleanup imports

* more

* add internal and enum env var support

* ruff cleanup

* more global imports

* revert telemetry, it lives in rx.Config

* minor fixes/cleanup

* i missed some refs

* fix darglint

* reload config is internal

* fix EnvVar name

* add test for EnvVar + minor typing improvement

* bool tests

* was this broken?

* retain old behavior

* migrate APP_HARNESS_HEADLESS to new env var system

* migrate more APP_HARNESS env vars to new config system

* migrate SCREENSHOT_DIR to new env var system

* refactor EnvVar.get to be a method

* readd deleted functions and deprecate them

* improve EnvVar api, cleanup RELOAD_CONFIG question

* move is_prod_mode back to where it was
2024-11-05 12:25:13 -08:00

42 lines
1.2 KiB
Python

"""Helpers for downloading files from the network."""
import httpx
from ..config import environment
from . import console
def _httpx_verify_kwarg() -> bool:
"""Get the value of the HTTPX verify keyword argument.
Returns:
True if SSL verification is enabled, False otherwise
"""
return not environment.SSL_NO_VERIFY.get()
def get(url: str, **kwargs) -> httpx.Response:
"""Make an HTTP GET request.
Args:
url: The URL to request.
**kwargs: Additional keyword arguments to pass to httpx.get.
Returns:
The response object.
Raises:
httpx.ConnectError: If the connection cannot be established.
"""
kwargs.setdefault("verify", _httpx_verify_kwarg())
try:
return httpx.get(url, **kwargs)
except httpx.ConnectError as err:
if "CERTIFICATE_VERIFY_FAILED" in str(err):
# If the error is a certificate verification error, recommend mitigating steps.
console.error(
f"Certificate verification failed for {url}. Set environment variable SSL_CERT_FILE to the "
"path of the certificate file or SSL_NO_VERIFY=1 to disable verification."
)
raise