Update Filters and Run Query Issue - LookApi function

I am trying to make this code work in my python script ( I have correctly built a yaml config file with the host, secret, and token. However, in the line

looker = LookApi(host=my_host, token=my_token, secret=my_secret)

I keep getting the error TypeError:init() got an unexpected keyword argument ‘host’

I have included a screenshot, above the screenshot is the line

from lookerapi import LookApi because putting LookerApi did not work.

Host, secret, and token, all have the correct strings in them. I cannot find further documentation on the LookApi function. Please advise.

13 replies

Userlevel 7
Badge +1

This is definitely the root of the problem— LookApi is a totally different thing from LookerApi, and wouldn’t expect to get the values you’re feeding it. You call LookApi to perform things against Looks, like you’d call the UserApi to perform a user action. LookerApi is what everything’s wrapped in.

What do you mean by it “did not work”? Curious if there’s something missing from that step!

Plus, quick plug for the semi-official python sdk here: which can be easily installed via pip install lookerapi and has a much simpler authentication flow. I’d definitely try that over the method you’re using.

Here is what happens when I run

from lookerapi import LookerApi

I do not understand this issue, I apologize for the basic question.

Also, while it is helpful to see another way of authenticating, I then have to find another way to update the filters on a run by run basis, is there a different or better way to do this? I feel like I am using old information.

Userlevel 7
Badge +1

That’s a good

Also, while it is helpful to see another way of authenticating, I then have to find another way to update the filters on a run by run basis, is there a different or better way to do this? I feel like I am using old information.

That’s a good point, let’s see if we can get this working before trying other options.

I’m just looking at that error— How did you install the looker api? Do you have the file in the directory you’re running this from, per ?

I just cloned the repo and ran from lookerapi import LookerApi and all ran smoothly, so I think you might be missing that file from the root directory. Try cloning the repo and then re-running 🙂

Userlevel 7
Badge +1

If you can’t get that to work, I can help you whip up an example of the same functionality with the python SDK that I linked to! Just keep me posted.

Now that all those .py files are in the same place as my ipynb the import line is working fine, I will try the rest of the code and post back here with any issues.

Thank you for your help, I have been struggling for a while here.

I got this error after fixing the code to your points, I am still just trying to get the looker.get_look_info() to run. Any suggestions on what to do to get the connection to work?

On another note, I have read the SDK page, how is that different/better than what I am doing? Will it make running this script for custom looks easier?

Userlevel 7
Badge +1

Generally, the SDK that I linked out to is easier to use overall, and the authentication steps are certainly easier.

The issue that you’re hitting is almost always related to the “API Host URL” setting in the Admin panel. What host URL are you using in your script, and what host URL do you see in the admin panel? Make sure that they match 🙂

So I imported lookerapi, downloaded all of the .py files from this page:

and I have tried to run the code, but I get the error:

AttributeError: module ‘lookerapi’ has no attribute ‘ApiClient’

But I have the file in the same folder as the ipynb. I do appreciate the continued help.

Userlevel 7
Badge +1

I think this could be a case of the confusion from the earlier attempts with the other python SDK you were using. Both have files, but they do very different things. Could you start from scratch with JUST the files from and see if that treats you better?

I’m not sure how jupyter works either, but I think you could just do pip install lookerapi and get up and running quicker that way, no manual downloads necessary.

I was finally able to connect to the API, but the code from this page for updating filters before running a look does not run, is this the code I should be working with? Is there another place to find code samples that use the SDK?

Userlevel 7
Badge +1

I don’t believe we have full samples like the one you’re referencing for the improved SDK, but you could totally use the as a template and rebuild it using the methods described here:

I think you’d need the look endpoint, query, create_query, and update_look in order to make it work— Each one of those links has examples of their use.

Thank you!