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

Linux服务器Python脚本requests-urllib3连接超时求助(Postman可正常请求)

Linux服务器上Python requests请求超时,但Postman能正常访问同一API

错误信息

A request error occurred: HTTPConnectionPool(host='10.88.64.79', port=8080): Error('<urllib3.connection.HTTPConnection object at 0x7f1d653b65b0>: Failed to establish a new connection: [Errno 110] Connection timed out'))

问题背景

使用Postman请求目标API URL可以正常获取IP分配详情,但在Linux服务器上运行Python脚本时出现上述连接超时错误,无法获取数据。

代码片段

import requests
def findip_ip_api(subnet_ip, subnet_mask):
    try:
        findip_url = "http://x.x.x.x:8080/findip/ip/{}?len={}".format(subnet_ip, subnet_mask)
        findip_response = requests.request("GET", findip_url, verify=False)
        ip_api_data = findip_response.json()['data']
    except requests.exceptions.HTTPError as e:
        raise SystemExit("An HTTP error occurred: {}".format(e))
    except requests.exceptions.RequestException as e:
        raise SystemExit("A request error occurred: {}".format(e))
    else:
        print(ip_api_data)

findip_ip_api('1.1.1.4','29')

预期响应(Postman返回结果)

{
    "data": [
        {
            "address": "x.x.x.x",
            "description": "interface \"Vlanxx\" (VRF <vrf name>) standby 75",
            "host": "<hostname>",
            "isDecommed": 1,
            "length": 29
        }
    ],
    "metadata": {
        "datasize": 55363258,
        "lastRefresh": 1702771027,
        "lastRefreshTime": "Sat 16 Dec 2023 23:57:07 GMT",
        "lastUpdate": 1674721862,
        "lastUpdateTime": "Thu 26 Jan 2023 08:31:02 GMT",
        "lookup": "1.1.1.4/29",
        "recordCount": 720907,
        "resultCount": 8
    }
}

恳请帮忙排查问题,谢谢!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.03 12:58:56