Secure Static IP for Python HTTPS using HTTPx & QuotaGuard Shield

Learn how to securely route Python HTTP traffic through a QuotaGuard Shield proxy using the HTTPx library.

Prerequisites

Python installed

Instructions

Run Example
QUOTAGUARDSHIELD_URL=... python app.py
Test in Docker
docker build -t qg-shield-python-https-httpx-example .
docker run -e QUOTAGUARDSHIELD_URL=... qg-shield-python-https-httpx-example

Code Samples

App.py
import 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)
Docker File
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"]