Model Not Found Error When Running a Looker Query via Python API

Hi everyone,

I’m currently working on integrating Looker with a FastAPI application using the Looker SDK version 4. I’ve created a function to execute a Looker query with a query_id, and I retrieve the results in JSON format. However, whenever I run the function, I consistently receive a “Model Not Found” error.

Here’s the function I’m using:

def get_data_from_looker(query_id=int):
try:
result = sdk.run_query(
query_id=query_id,
result_format=“json”,
limit=5000
)
count = len(result)
return {“query_id”: query_id, “result_count”: count, “query_result”: result}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))

Error Message: Model Not Found

What I’ve Already Checked:

  1. The query_id is correct and exists in Looker.
  2. Authentication with the Looker SDK (initialized with looker_sdk.init40(config_file=‘./looker.ini’)) works fine.
  3. The model used by this query is correctly defined in Looker, and permissions are in place.

Hi

there seems to be something wrong withe Model as the error message suggests.

That a query exists and is created does not mean it works.

I would advise on using the API Explorer on your instance and follow the steps of Create Query, Get Query (with the previously created query) and then Run Query - if this works, it will work in Python too.

I just tried for feasibility on my mind and even though I could create and get a query on nonsense model and fields, it threw an error when trying to run a query.

Hope that helps!

Thank you for your response. I used the API Explorer of the instance, and it returns the data correctly…

I tried another method …

I can execute sdk.create_query_task and sdk.query_task_results, but I don’t have the data. When looking at the task information with sdk.query_task, we see a status=‘error’.