如何为Swagger生成的Python API客户端设置超时?

发布于 2025-01-23 07:02:33 字数 53 浏览 4 评论 0原文

默认情况下,Swagger Codegen Python客户端的超时时间很高,我想设置其值。

By default, the swagger codegen python client has a high timeout and I would like to set its value.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

毅然前行 2025-01-30 07:02:33

事实证明,您可以使用以下参数来配置请求:

  • _request_timeout(int)此请求的超时设置。如果提供了一个数字,则将是总请求超时。它也可以是(连接,读)超时的一对(元组)。
  • _PRELOAD_CONTENT(bool)如果false,则urllib3.httpresponse对象将在不读取/解码响应数据的情况下返回。默认是正确的。
  • _return_http_data_only(bool)如果为true,请返回响应数据,而无需头部状态代码和标题

如何使用它们:

// Configure client
configuration = Configuration()
configuration.host = my_host
configuration.api_key['Apikey'] = my_apikey

// Get API instance
api_client = ApiClient(configuration)
api_instance = MyAPIcontroller(api_client)

// Make the request
data = MyData()
api_response = api_instance.my_endpoint(data, _request_timeout=10)

where:

  • myapicontroller是由Swagger Code创建的控制器类, >/Controller 客户端的文件夹
  • myDatamy_apikey是您可以在请求中发送的数据的示例。您可能不需要它们,这取决于您的端点定义。

Turns out you can use the following parameters to configure the request:

  • _request_timeout (int) Timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of (connection, read) timeouts.
  • _preload_content (bool) If False, the urllib3.HTTPResponse object will be returned without reading/decoding response data. Default is True.
  • _return_http_data_only (bool) If True, returns response data without head status code and headers

How to use them:

// Configure client
configuration = Configuration()
configuration.host = my_host
configuration.api_key['Apikey'] = my_apikey

// Get API instance
api_client = ApiClient(configuration)
api_instance = MyAPIcontroller(api_client)

// Make the request
data = MyData()
api_response = api_instance.my_endpoint(data, _request_timeout=10)

Where:

  • MyAPIcontroller is the controller class created by Swagger codegen in the /controllers folder of your client
  • MyData and my_apikey are examples of data you can send in your request. You may not need them, it depends on your endpoint definition.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文