Python请求get失败,出现连接错误,但url有效

2024-05-23 19:53:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在通过api连接weblogic服务器以收集服务器的状态。如果我从浏览器中尝试并且能够得到响应,那么restapi就可以正常工作了。在

我编写了一个python脚本来进行这些restapi调用。但是他们因为连接失败而失败。在

Error - requests.exceptions.ConnectionError: ('Connection aborted.', error(10054, 'An existing connection was forcibly closed by the remote host'))

我们的环境中没有代理设置。在

这是示例代码

url = 'http://' + host + ':' + port + url
response = requests.get(url, auth=(username, password),
                         headers=headers)

# Check for HTTP codes other than 200
if response.status_code != 200:
    print('Status:', response.status_code, 'Headers:', response.headers, 'Error Response:', response.json())

我无法确定这个问题是来自weblogic还是来自我编写的脚本,因为如果我从浏览器中点击,每次都能得到正确的响应。在

我正在尝试获取的Weblogic API-http://localhost:7001/management/wls/latest/deployments

有人面对过这种情况并能解决这个问题吗?在

谢谢!在


Tags: 服务器脚本apirestapihttphosturlresponse