A proxy setup in Airflow is the configuration that routes your tasks' outbound HTTP requests through a proxy server. The setting can live in three places: the worker's environment variables, a Connection's extra field or the task's own code. The trap is in the environment variables. If the NO_PROXY list is incomplete, an HTTPS_PROXY given to the worker can also apply to Airflow's own internal HTTP traffic. This post covers those three places, where to store the password and how to retry on proxy errors.
The three places for a proxy
Where you write the proxy in Airflow decides which tasks the setting affects. An environment variable affects every process on the worker, a Connection the tasks that use it, and task code only its own request.
| Place | Scope | Where the password lives | Good fit |
|---|---|---|---|
| Worker environment variable | Every process on the worker | In the service definition, plain text | All egress through one proxy |
| Connection extra field | Tasks using that Connection | Connection store | HttpOperator and HttpHook tasks |
Task code (requests) | That request only | A separate Connection | Code inside @task or PythonOperator |
We recommend the Connection. The setting is visible wherever the proxy is used. Internal traffic stays untouched, and switching country or account means changing one record.
Worker environment variables
Most Python HTTP libraries read the HTTP_PROXY, HTTPS_PROXY and NO_PROXY variables on their own. In Requests this behavior is on by default. You write the variables into the worker's service definition: environment in Docker Compose, the pod's env field in Kubernetes.
export HTTP_PROXY="http://user:pass@pr.proxynet.io:8000"
export HTTPS_PROXY="http://user:pass@pr.proxynet.io:8000"
export NO_PROXY="localhost,127.0.0.1,airflow-apiserver,.svc.cluster.local,169.254.169.254"The problem is that the worker runs more than task code. In Airflow 3, a task reports its state to the API server over HTTP and fetches Connections from there too. That address is set in [core] execution_api_server_url. If it is not in NO_PROXY, this internal request can go to the proxy as well. Secrets Backend clients and the cloud metadata address (169.254.169.254) also speak HTTP.
Connections to the metadata database (PostgreSQL, MySQL) and Redis are not HTTP, so these variables do not affect them. What belongs in NO_PROXY are internal addresses that speak HTTP: the API server, the Secrets Backend, internal service domains.
NO_PROXY matching differs by library. A domain that starts with a dot, a CIDR range and a port do not give the same result everywhere. We covered the details in Why the HTTP_PROXY variable is not working. If some tasks should run without a proxy, use a Connection instead of a global variable.
proxies in the Connection extra field
HttpHook, and the HttpOperator built on it, read the proxies key in the Connection's extra field. The value is written straight into the Requests session's proxies dictionary. The provider source also accepts the key spelled proxy. This support arrived in apache-airflow-providers-http 4.9.0. Older versions read the extra field as HTTP headers, and proxies is not applied as a proxy.
To define a Connection through an environment variable, you write an uppercase variable whose name starts with AIRFLOW_CONN_. The value can be JSON:
export AIRFLOW_CONN_PRICE_API_TR='{
"conn_type": "http",
"host": "api.example.com",
"schema": "https",
"extra": {
"proxies": {
"http": "http://user:pass@pr.proxynet.io:8000",
"https": "http://user:pass@pr.proxynet.io:8000"
}
}
}'The schema field is the target API's scheme, not the proxy's. The proxy URL still starts with http://, because a request to an HTTPS target opens a CONNECT tunnel at the proxy. Write both keys in the dictionary. With only http, the HTTPS request goes either to the environment variable or out directly.
The proxy is invisible on the DAG side. The task only knows the Connection ID:
from datetime import datetime, timedelta
from airflow.providers.http.operators.http import HttpOperator
from airflow.sdk import dag
@dag(
schedule="0 6 * * *",
start_date=datetime(2026, 12, 1),
catchup=False,
default_args={"retries": 3, "retry_delay": timedelta(minutes=2)},
)
def price_api():
HttpOperator(
task_id="price_tr",
http_conn_id="price_api_tr",
endpoint="v1/prices",
method="GET",
)
price_api()Precedence matters. The hook passes the Connection's proxies value to the request explicitly. The environment variable only fills in a scheme missing from the dictionary. In our test, with a different HTTP_PROXY set in the environment, the request went through the Connection's proxy. An address on the NO_PROXY list also went through the Connection proxy: NO_PROXY only bypasses a proxy that comes from the environment.
With requests in task code
If you use Requests inside @task or PythonOperator, the extra field is not read automatically. You set up the proxy yourself. The clean way is to keep the proxy credentials in a separate Connection. The password goes into the Connection's password field and is turned into a URL in code:
export AIRFLOW_CONN_PROXY_TR='{"conn_type": "generic", "login": "user",
"password": "pass@123", "host": "pr.proxynet.io", "port": 8000}'from datetime import timedelta
from urllib.parse import quote
import requests
from airflow.exceptions import AirflowFailException
from airflow.sdk import BaseHook, task
def proxy_from(conn_id: str) -> dict:
c = BaseHook.get_connection(conn_id)
url = f"http://{quote(c.login, safe='')}:{quote(c.password, safe='')}@{c.host}:{c.port}"
return {"http": url, "https": url}
@task(retries=3, retry_delay=timedelta(minutes=2))
def fetch_prices():
try:
r = requests.get(
"https://api.example.com/v1/prices",
proxies=proxy_from("proxy_tr"),
timeout=(5, 30),
)
except requests.exceptions.ProxyError as e:
if "407" in str(e):
# Wrong credentials: retrying will not fix it
raise AirflowFailException("Proxy authentication rejected") from e
raise
r.raise_for_status()
return r.json()quote() turns the @ in the password into %40. In our test, Requests 2.34.2 also split an unencoded @ correctly. Another tool reading the same URL may not, so encode it. In Airflow 2, BaseHook is imported from airflow.hooks.base.
Pass the proxy per request with proxies=, not through Session.proxies. If HTTPS_PROXY is set on the worker, the environment variable overrides Session.proxies. In our test, that session went to the environment proxy. The details are in using a proxy with Python Requests.
Storing the password
Airflow masks the password field of every Connection a task accesses in the logs. In the extra field, only keys whose name contains a sensitive word are masked: password, secret, token, api_key and similar. proxies is not on that list. If the proxy URL in extra gets printed to the log, the password is exposed.
There are two fixes. The first is to add the word proxies to the AIRFLOW__CORE__SENSITIVE_VAR_CONN_NAMES variable. Airflow then treats an extra field with that name as sensitive too. The second is to keep the password in a separate Connection's password field, as in the previous section.
Wherever the Connection itself lives, it should not enter the source code. A proxy password written into a DAG file, an Airflow Variable or the repository is open to everyone who reads it. In production, keep Connections in a Secrets Backend: HashiCorp Vault, AWS SSM Parameter Store or Google Secret Manager. Airflow pulls the Connection from there by its ID. The DAG code does not change.
Country egress per task
If different tasks should exit from different countries, create a separate Connection for each exit: proxy_tr, proxy_de, proxy_us. The task only picks the Connection ID. The country targeting syntax is in your provider's docs and is written once into the Connection's username or address.
An environment variable cannot do this. A worker carries a single HTTPS_PROXY value, and every task on it exits from the same country. For a DAG that collects prices or content that vary by country, a Residential Proxy lets you pick a country per Connection.
It is different when the target API expects calls from a fixed IP. Some APIs add the client's IP to an allowlist. In that case every scheduled run must exit from the same address, and a rotating pool will not work.
Retry settings
When the proxy connection cannot be established, Requests raises ProxyError and the task fails. Airflow reruns the task retries times, waiting retry_delay between attempts. The default retries value is 0. Without a setting, a single timeout loses that day's run.
| Parameter | What it does | Recommendation |
|---|---|---|
retries | How many times to retry after a failure | 2-3 |
retry_delay | Wait between attempts (default 300 seconds) | 1-5 minutes |
retry_exponential_backoff | Lengthens the wait on each attempt | Turn on if the target API is rate-limited |
execution_timeout | Upper limit for a single run | Longer than the request's timeout |
In the Airflow 3.4 docs, retry_exponential_backoff takes a number: 0 is off, 2.0 is standard exponential growth. Older versions take True. Also pass timeout=(connect, read) to the request. Without a timeout, Requests can wait minutes for a response.
Not every error is worth a retry. On an HTTPS target, wrong credentials produce a ProxyError with the message Tunnel connection failed: 407. This error is a subclass of ConnectionError, and Airflow retries it too. Three attempts return the same 407. The AirflowFailException in the example stops the task without spending the retries. The causes of a 407 are in the HTTP 407 error post.
Troubleshooting
The task log tells you which layer the proxy error is in. Find the symptom in the table and rule out the causes one by one.
| Symptom | Likely cause | Fix |
|---|---|---|
| Task cannot reach the API server | Internal address missing from NO_PROXY | Add the API server name to NO_PROXY |
| Request goes out without the proxy | Provider older than 4.9.0, or https key missing | Upgrade the provider, write both keys |
Request in @task goes to the environment proxy | Proxy set via Session.proxies | Pass proxies= per request |
Tunnel connection failed: 407 | Wrong username or password | Fix the Connection, don't wait on retries |
ReadTimeout | Slow target or short timeout | Increase the read timeout |
| Password visible in the log | proxies key is not masked | Add it to SENSITIVE_VAR_CONN_NAMES |
To see which proxy was used, send a request from the task to an address that returns the outgoing IP and log the result. If the IP comes from the country of the Connection's proxy, the setup is correct.
How we tested
We did not install Airflow or run the DAG. On December 2, 2026, we tested only the Requests layer, with Python 3.13.17 and Requests 2.34.2. We set up two local test proxies that logged the incoming request and the Proxy-Authorization header. We gave one to the environment variable and the other to the session or the request.
We took the lines of HttpHook that build the session verbatim from the source in the apache/airflow repository: the session.proxies assignment and the merge_environment_settings(proxies=session.proxies) call. With this setup, the request went through the Connection proxy. A plain Session.proxies went to the environment proxy, and a per-request proxies= went to the right proxy. On an HTTPS target, a wrong password raised ProxyError.
The bottom line
Write the proxy into a Connection, keep the credentials in a Secrets Backend and use only the Connection ID in the task. Give retries and timeout values to every task that uses a proxy. Above all, if you set a global HTTPS_PROXY, put Airflow's internal addresses in NO_PROXY. For APIs that require a fixed IP, a ISP Proxy keeps the same address with a single Connection.
Sources
- Airflow http provider, HTTP Connection extra fields: airflow.apache.org
- Airflow docs, masking sensitive data: airflow.apache.org
- HttpHook source code, apache/airflow: github.com
- Requests docs, Proxies section: requests.readthedocs.io
Frequently asked questions
Does Airflow HttpOperator support proxies?
Yes. HttpOperator runs on HttpHook, and the hook reads the proxies key in the Connection's extra field. This support arrived in apache-airflow-providers-http 4.9.0. Write both the http and the https key in the dictionary. Older provider versions read the extra field as headers and apply no proxy. So check the version first.
Should I set the proxy on the worker or in a Connection?
In a Connection. An environment variable on the worker affects every process on that worker, including Airflow's own internal HTTP traffic. A Connection affects only the tasks that use it. By creating a separate Connection for each exit, you can give tasks different countries or accounts. An environment variable only fits when all egress must go through one proxy.
Which addresses should go in NO_PROXY?
Internal addresses that speak HTTP. In Airflow 3, the API server comes first. Add the Secrets Backend address, internal service domains, localhost and, in the cloud, the metadata address 169.254.169.254. Connections to the metadata database and Redis are not HTTP, so the proxy variables do not affect them.
Can the proxy password show up in Airflow logs?
It can. Airflow always masks a Connection's password field, but in the extra field it only hides keys whose name contains a sensitive word. proxies is not on that list. Add proxies to the AIRFLOW__CORE__SENSITIVE_VAR_CONN_NAMES variable, or keep the password in a separate Connection's password field.
How many times is a task retried after a proxy error?
As many times as retries says. The default is 0, so without a setting the task fails on the first error. Between attempts Airflow waits retry_delay, 300 seconds by default. For permanent errors such as a wrong password, you can skip pointless attempts by raising AirflowFailException.
Can each task exit from a different country?
Yes, by creating a separate Connection for each country. Give them IDs such as proxy_tr and proxy_de, and pick the matching Connection in each task. The country targeting syntax is in your provider's docs and is written once into the Connection. A single worker environment variable cannot do this, because the variable gives every task on it the same proxy.




