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

Palantir-Foundry Transform中用requests调用API遇连接错误的排查

在Palantir Foundry Transform中解决HTTP请求ConnectionError的方案

问题本质

这是配置问题,Foundry的Transform运行环境默认处于网络隔离状态,不允许直接发起外部HTTP/HTTPS请求,必须通过管理员配置出站网络策略放行目标域名。

解决步骤

  • 确认需要访问的API目标域名(示例中为api.github.com)及端口(HTTPS默认443)
  • 联系Foundry管理员,在Foundry管理控制台的「出站网络策略」中添加规则:指定允许发起请求的Transform所属项目/仓库,同时放行目标域名和端口
  • (环境依赖)若你的Foundry环境要求通过内部代理访问外部网络,需在代码中配置代理(代理地址请咨询管理员):
    from transforms.api import Input, Output, transform_pandas
    import requests
    
    @transform_pandas(
        Output("..."),
        df=Input("..."),
    )
    def compute(df):
        proxies = {
            'https': 'http://your-foundry-proxy:port'
        }
        # 添加超时避免流水线挂起
        response = requests.get('https://api.github.com', proxies=proxies, timeout=10)
        print(response.content)
        return df
    

额外注意事项

  • 敏感信息(如API密钥)不要硬编码,使用Foundry的秘密管理功能存储,通过transforms.api.secret调用
  • 确保API请求是幂等的,防止流水线重试时重复触发非预期操作
  • 务必设置请求超时时间,避免因API无响应导致流水线任务挂起

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 06:15:45