首页 > 解决方案 > 通过 Jenkins 连接到远程 API 时 Python 请求抛出连接错误

问题描述

我正在运行一个在远程主机上调用 API 的 python 脚本。虽然这在本地运行良好,但当我从 Jenkins 作为作业运行此脚本时它会失败。它无法连接到远程主机。

我打算自动化这个过程,因此想在 Jenkins 上运行它。我尝试将证书导入 Jenkins 中的 keytool,认为这是某种证书问题,但看起来 ping 本身无法访问远程主机。

url = https://remotehost:remoteport/api
payload = {
           some prams to filter request
          }

response = requests.get(url, params=payload,auth=HTTPBasicAuth(USER, PASS ))

构建失败并出现以下错误:

requests.exceptions.ConnectionError:
HTTPConnectionPool(host='remotehost', port=remoteport): 
Max retries exceeded with url: /api/params 
(Caused by NewConnectionError('<urllib3.connection.HTTPConnection 
object at 0x7fc010cb8dd8>: Failed to establish a new connection: 
[Errno 110] Connection timed out',))
Build step 'Execute shell' marked build as failure

我不确定这是否会在 Jenkins 中进行更改,因为它在本地运行良好?如果是,任何关于我应该在哪里进行设置的指针?

标签: python-3.xjenkinspython-requests

解决方案


推荐阅读