Learn how to securely route Python HTTP traffic through a QuotaGuard Shield proxy using the HTTPx library.
Python installed
QUOTAGUARDSHIELD_URL=... python app.pydocker build -t qg-shield-python-https-httpx-example .
docker run -e QUOTAGUARDSHIELD_URL=... qg-shield-python-https-httpx-exampleimport os
import httpx
QUOTAGUARD_URL = os.getenv("QUOTAGUARDSHIELD_URL", "")
TEST_URL = "https://ip.quotaguard.com/"
if not QUOTAGUARD_URL:
print("Error: QUOTAGUARD_URL environment variable not set.")
exit(1)
try:
response = httpx.get(TEST_URL, proxy=QUOTAGUARD_URL)
print("Response from QuotaGuard:")
print(response.text)
except Exception as e:
print("Request failed:")
print(e)FROM python:latest
WORKDIR /app
# Install dependencies
RUN pip install httpx
# Copy app code
COPY app.py .
# Set the default command
CMD ["python", "app.py"]