Update Filters and Run Query Issue - LookApi function

low_priority
done
reply
(Jake Wellins) #1

I am trying to make this code work in my python script (https://github.com/llooker/python_api_samples/blob/master/update_filters_and_run_query.py). 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.

0 Likes

(Izzy) #2

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: https://github.com/llooker/python_sdk 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.

0 Likes

(Jake Wellins) #3

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.

0 Likes

(Izzy) #4

That’s a good [quote=“Jake_Wellins, post:3, topic:11928”]
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.
[/quote]

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 lookerapi.py file in the directory you’re running this from, per https://github.com/llooker/python_api_samples#getting-started ?

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

0 Likes

(Izzy) #5

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.

0 Likes

(Jake Wellins) #6

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.

1 Like

(Jake Wellins) #7

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?

0 Likes

(Jake Wellins) #8

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?

0 Likes

(Izzy) #9

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 :slight_smile:

0 Likes

(Jake Wellins) #10

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 api_client.py file in the same folder as the ipynb. I do appreciate the continued help.

0 Likes

(Izzy) #11

I think this could be a case of the confusion from the earlier attempts with the other python SDK you were using. Both have lookerapi.py files, but they do very different things. Could you start from scratch with JUST the files from https://github.com/llooker/python_sdk 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.

0 Likes

(Jake Wellins) #12

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?

0 Likes

(Izzy) #13

I don’t believe we have full samples like the one you’re referencing for the improved SDK, but you could totally use the update_filters_and_run_query.py 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.

0 Likes

(Jake Wellins) #14

Thank you!

0 Likes