Read a CSV Through a Proxy with pandas and Requests
Fetch a CSV with a configured Requests transport, check its HTTP result, and give pandas a byte buffer for parsing.
When the HTTP route needs explicit proxy control, retrieve the CSV first and let pandas handle the resulting bytes:
from io import BytesIO
import pandas as pd
import requests
route = {
'http': 'http://proxy.example:8080',
'https': 'http://proxy.example:8080',
}
with requests.get(
'https://data.example/report.csv',
proxies=route,
timeout=(5, 30),
) as response:
response.raise_for_status()
frame = pd.read_csv(BytesIO(response.content), encoding='utf-8')
The proxy handles transport; the HTTP proxy list supplies endpoint candidates for a public HTTP route. pandas receives a file-like object and applies its normal delimiter, column, encoding and data-type options.
Checking the HTTP result before parsing avoids treating an obvious HTTP error body as a table. Also inspect unexpected content: a login or policy page can return 200 and still be HTML instead of the requested CSV.
For HTTP URLs, read_csv's storage_options are forwarded as request headers. That interface is not a Requests-style proxies mapping.
A buffer has no archive filename to guide compression inference. Specify compression when the retrieved payload requires it. The same fetch-first arrangement works with read_excel and a byte buffer, using the spreadsheet engine appropriate to that format.
This example keeps the entire response in memory. For a large export, stream it into a managed local file and parse that file, with chunking where the data workflow supports it.