[Python] Send an HTTP request with Basic authentication

Created on November 29, 2026

With the Requests library, you can pass an HTTPBasicAuth object to the auth argument of requests.get() to send Basic authentication credentials.

Replace the example URL and credentials with the HTTPS endpoint and credentials for your service.

import requests
from requests.auth import HTTPBasicAuth

basic_auth = HTTPBasicAuth("tom", "example-password")
response = requests.get("https://example.com/", auth=basic_auth, timeout=10)
response.raise_for_status()

print(response.text)
Python