空手道 DSL:获取连接超时错误

Posted

技术标签:

【中文标题】空手道 DSL:获取连接超时错误【英文标题】:Karate DSL: Getting connection timeout error 【发布时间】:2020-05-02 04:59:44 【问题描述】:

我正在致力于自动化托管在中国服务器中的 API,当我发送请求时,它会抛出超时异常 (org.apache.http.conn.HttpHostConnectException)。

我的功能文件:

Background: 
  * url 'http://myurl'
  * configure connectTimeout = 500000

Scenario: Get Client details
  Given path '/clients'
  And header Authorization = 'sdssSSLwWDSD'
  When method get
  Then match response.client_id == 'TestId'

错误详情:

11:22:30.347 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection request: [route: s->https://myurl.com][total kept alive: 0; route allocated: 0 of 5; total allocated: 0 of 10]
11:22:30.365 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: s->https://myurl.com][total kept alive: 0; route allocated: 1 of 5; total allocated: 1 of 10]
11:22:30.365 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Opening connection s->https://myurl.com
11:22:30.384 [main] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connecting to myurl.com/54.223.191.33:443
11:22:30.384 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory - Connecting socket to myurl.com/54.223.191.33:443 with timeout 500000
11:22:51.407 [main] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connect to myurl.com/54.223.191.33:443 timed out. Connection will be retried using another IP address
11:22:51.407 [main] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connecting to myurl.com/52.80.167.86:443
11:22:51.408 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory - Connecting socket to myurl.com/52.80.167.86:443 with timeout 500000
11:23:12.438 [main] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-0: Shutdown connection
11:23:12.439 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Connection discarded
11:23:12.440 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: s->https://myurl.com:443][total kept alive: 0; route allocated: 0 of 5; total allocated: 0 of 10]
11:23:12.440 [main] ERROR com.intuit.karate - org.apache.http.conn.HttpHostConnectException: Connect to myurl.com [myurl.com/54.223.191.33, myurl.com/52.80.167.86] failed: Connection timed out: connect, http call failed after 42094 milliseconds for URL: https://myurl.com/tnc/v1/tnc/all
11:23:12.441 [main] ERROR com.intuit.karate - http request failed: 
org.apache.http.conn.HttpHostConnectException: Connect to myurl.com:443 [myurl.com/54.223.191.33, myurl.com/52.80.167.86] failed: Connection timed out: connect
11:23:12.601 [Finalizer] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection manager is shutting down
11:23:12.601 [Finalizer] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection manager shut down
html report: (paste into browser to view) | Karate version: 0.9.4

我已经尝试过的: 我尝试将超时配置为最大值,如下所示:

 * configure connectTimeout = 500000 

没用。

但是,当从 Postman 尝试相同的请求时,工作正常,我在 2000 毫秒内得到响应。

不知道我哪里错了。

【问题讨论】:

【参考方案1】:

您很可能有一个公司 HTTP 代理。

参考:https://github.com/intuit/karate#configure

* configure proxy = 'http://my.proxy.host:8080'

【讨论】:

以上是关于空手道 DSL:获取连接超时错误的主要内容,如果未能解决你的问题,请参考以下文章

连接池异常:无法获取连接,池错误超时等待空闲对象

linux 网络连接超时

Beanstalk获取套接字错误110:连接超时

KnexTimeoutError: Knex: 获取连接超时

heroku 连接超时(连接超时)

适用于 excel 的 BigQuery 连接器 - 请求失败:错误。无法执行查询。获取 URL 时超时