Samuel O.D.
Samuel O.D.

Reputation: 393

How can I set a timeout for Swagger generated python API client?

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

Upvotes: 1

Views: 3079

Answers (1)

Samuel O.D.
Samuel O.D.

Reputation: 393

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.

Upvotes: 1

Related Questions