You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Cloud Composer Airflow运行Python调用API报Errno 101连接超时如何解决

Cloud Composer Airflow 调用外部API连接超时问题

我在使用Google Cloud Composer提供的Airflow运行Python代码调用API时,持续出现[Errno 101] Connection timed out报错。

关联代码

r1 = requests.post(
    url1,
    params=request1_params,
    headers=request1_headers
)

a_token = r1.json().get('access_token')

触发DAG后的错误日志

[2021-10-04 01:21:33,056] {taskinstance.py:1152} ERROR - HTTPSConnectionPool(host='xxx.com', port=443): Max retries exceeded with url: /sf/xxx/token?grant_type=password&username=???%40???&password=???%2???&client_id=????&client_secret=???? (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f43a2958860>: Failed to establish a new connection: [Errno 110] Connection timed out',))
Traceback (most recent call last):
File "/opt/python3.6/lib/python3.6/site-packages/urllib3/connection.py", line 170, in _new_conn
(self._dns_host, self.port), self.timeout, **extra_kw
File "/opt/python3.6/lib/python3.6/site-packages/urllib3/util/connection.py", line 96, in create_connection
raise err
File "/opt/python3.6/lib/python3.6/site-packages/urllib3/util/connection.py", line 86, in create_connection
sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out

问题定位与解决

最初排查时猜测是请求需要配置代理,最终定位问题根源为当前Airflow使用的私有网络缺少NAT配置,完成NAT配置并安装对应依赖库后,API请求已可正常发送。

内容的提问来源于stack exchange,提问作者Yohandy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 01:09:00