Setting a timeout parameter for the run_look function with the SDK

I am interested in exporting a Look to a CSV file using the Looker SDK with the run_look function. When I use the limit parameter, I receive an error that the read timed out. When I remove the limit parameter, the query works, but defaults to the limit set in the Look.

According to support, the reason the call works without the limit is because the results are already cached. When adding a limit to the query, it has to regenerate the results from the Look taking longer than 10 seconds which is the default timeout value.

Looker Support pointed me towards this article which seemingly allows you to add a timeout parameter to the run_look function, but it does not give enough explanation for this. 

Does anyone know how I can add the timeout parameter to the run_look function?

This is my code snippet so far: 

    contents = sdk.run_look(
look_id = id,
result_format = "csv",
apply_formatting = False,
limit = 100)

And this is the code from the Looker article about using a timeout parameter:

run_inline_query({stuff}, {timeout: 3600}) 

1 5 3,050
5 REPLIES 5

Generally there are three options.

1) Define the timeout  in the .ini file. This applies to all calls unless a timeout is specified at the method call site. 

2) Create a class that implements the PTransportSettings protocol where you set the timeout. This can then be passed as a transport_options argument when desired, allowing you to set a longer timeout for specific method calls.


import looker_sdk
from looker_sdk import models
from looker_sdk.rtl import transport

class MyTransportOptions(transport.PTransportSettings): timeout = 600

sdk = looker_sdk.init40()
me = sdk.me()

look = sdk.run_look(look_id=1995,result_format="png", limit=-1, transport_options=MyTransportOptions)
print(look)

3) Assign the desired timeout while instantiating the SDK. This will have to be done without using our helper methods (init31/init40). 

settings = api_settings.ApiSettings("looker.ini", "looker")
settings.timeout = 5000
transport = requests_transport.RequestsTransport.configure(settings)
methods31.Looker40SDK(
  auth_session.AuthSession(settings, transport, serialize.deserialize40, "4.0"),
  serialize.deserialize40,
  serialize.serialize,
  transport,
  "4.0",
)

The first two would be my personal recommendations.

Just want to cite Jax for explanation and example code. 

Thank you for the timely response. I am going with method 2 as I cannot change the timeout variable for all the SDK requests.

After importing transport, declaring the class with the timeout, and trying to print the look using the exact lines you have (just with a different Look ID), I am receiving this error: 

AttributeError: type object 'MyTransportOptions' has no attribute 'get'

Is there something else I am missing?

How I can add the timeout parameter in the api calls written in  Looker Extension created with React JS and ‘@looker/embed-sdk’.

Could you please help me on that.

I tried like this

coreSDK.ok(coreSDK.run_inline_query(inlineQueryData), {timeout: 3600})

but still getting the timeout error.

a co-worker helped me with this, this is how you set a timeout:
 

look = self.get_conn().run_look(look_id=int(look_id),                                       result_format=result_format,                                       apply_formatting=apply_formatting,                                       limit=limit,                                       transport_options={"timeout": int(timeout)})