The Looker API v3.0 has a custom authentication scheme which requires a SHA-1 hash of the query parameters. Does the generated code know how to do this or I need to modify the generated code.
Generating Clients/SDKs Using Swagger Codegen
I am trying to generate a client using swagger-codegen in aspnetcore
. When I generate the client everything gets generated but all the code in the controllers is filled with TODO comments rather than the actual code for the method:
Example:
public virtual IActionResult Login([FromQuery]string clientId, [FromQuery]string clientSecret)
{
//TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(200, default(AccessToken));
//TODO: Uncomment the next line to return response 400 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(400, default(Error));
//TODO: Uncomment the next line to return response 404 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
// return StatusCode(404, default(Error));
string exampleJson = null;
exampleJson = "{\n \"access_token\" : \"access_token\",\n \"token_type\" : \"token_type\",\n \"expires_in\" : 0\n}";
var example = exampleJson != null
? JsonConvert.DeserializeObject<AccessToken>(exampleJson)
: default(AccessToken);
//TODO: Change the data returned
return new ObjectResult(example);
}
However, when I generate the client using .net starndard, everything gets generated fine and I can consume the API endpoints as documented.
Here is the command I’m running:
swagger-codegen generate -i swagger.json -l aspnetcore -o LookerAPI
Does the swagger file provided by looker (API 3.0) support dotnet core? Seems like it might not be completed yet…
Chat would be better. Where can we get connected in chat. ?
Could you come on chat and we’ll work on this issue with you
Scott input was valuable and I was able to get swagger.json not I have moved to next level where I am writing the API script to connect looker via python. I was getting the error. The error is very much similar in early post. But I didn’t see any solution on that but people have overcome this.
to answer second question I even ran the curl via terminal and I get similar error which read as
HTTP/1.1 401 Unauthorized
Content-Type: application/json;charset=utf-8
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
Content-Length: 84
curl
or wget
: curl -0 https://master.dev.looker.com:19999/api/3.0/swagger.json > swagger.json
.
The response you pasted in here seems to be related to something else. You’re getting a 404, which means the resource you’re looking for is simply not there. Please reach out via help.looker.com or pop on chat so we can have a look at your code.
I am getting 404 error similar well not similar its same as mentioned by
raise ApiException(http_resp=r)
ApiException: (404)
Reason: Not Found
HTTP response headers: HTTPHeaderDict({‘Vary’: ‘Accept-Encoding’, ‘Content-Length’: ‘69’, ‘Content-Type’: ‘application/json;charset=utf-8’, ‘X-Content-Type-Options’: ‘nosniff’})
HTTP response body: {“message”:“Not found”,“documentation_url”:“http://docs.looker.com/”}
Take a look at Step 2 under the “Setup” section.
https://<your_looker_endpoint>:19999/api/3.0/swagger.json
You can retrieve the JSON from the above-mentioned endpoint.
Hello
I am stuck with the python script here. when I run the client side I get below error
Traceback (most recent call last):
File “/Users/sv/LookerPython/LKCONNECT2.py”, line 15, in
token = unauthenticated_authApi.login(client_id=client_id, client_secret=client_secret)
File “/Users/sv/LookerPython/swagger_client/apis/api_auth_api.py”, line 122, in login
callback=params.get(‘callback’))
File “/Users/sv/LookerPython/swagger_client/api_client.py”, line 322, in call_api
response_type, auth_settings, callback)
File “/Users/sv/LookerPython/swagger_client/api_client.py”, line 149, in __call_api
post_params=post_params, body=body)
File “/Users/sv/LookerPython/swagger_client/api_client.py”, line 358, in request
body=body)
File “/Users/sv/LookerPython/swagger_client/rest.py”, line 208, in POST
body=body)
File “/Users/sv/LookerPython/swagger_client/rest.py”, line 177, in request
raise ApiException(http_resp=r)
ApiException: (404)
Reason: Not Found
HTTP response headers: HTTPHeaderDict({‘Vary’: ‘Accept-Encoding’, ‘Content-Length’: ‘69’, ‘Content-Type’: ‘application/json;charset=utf-8’, ‘X-Content-Type-Options’: ‘nosniff’})
HTTP response body: {“message”:“Not found”,“documentation_url”:“http://docs.looker.com/”}
Finally I was able to make till end. Thanks to all support.
Now I am stuck with testing my Looker_Connect.py
when I run the .py code I am getting error as below Help!!!
Traceback (most recent call last):
File “/Users/sv/LookerPython/LKCONNECT2.py”, line 15, in
token = unauthenticated_authApi.login(client_id=client_id, client_secret=client_secret)
File “/Users/sv/LookerPython/swagger_client/apis/api_auth_api.py”, line 122, in login
callback=params.get(‘callback’))
File “/Users/sv/LookerPython/swagger_client/api_client.py”, line 322, in call_api
response_type, auth_settings, callback)
File “/Users/sv/LookerPython/swagger_client/api_client.py”, line 149, in __call_api
post_params=post_params, body=body)
File “/Users/sv/LookerPython/swagger_client/api_client.py”, line 358, in request
body=body)
File “/Users/sv/LookerPython/swagger_client/rest.py”, line 208, in POST
body=body)
File “/Users/sv/LookerPython/swagger_client/rest.py”, line 177, in request
raise ApiException(http_resp=r)
ApiException: (404)
Reason: Not Found
HTTP response headers: HTTPHeaderDict({‘Vary’: ‘Accept-Encoding’, ‘Content-Length’: ‘69’, ‘Content-Type’: ‘application/json;charset=utf-8’, ‘X-Content-Type-Options’: ‘nosniff’})
HTTP response body: {“message”:“Not found”,“documentation_url”:“http://docs.looker.com/”}
William - thanks for your input this was informative but it didn’t help me completely.
Appreciated. This is going to help me in future thou 🙂
How and from where do I get the swagger.json file and place the similar as below ?
/Users/scott/Desktop/looker_python_client/swagger.json
I am stuck with this file from few days. Can you help me out?
Cheers
VS
William_Lane thanks for the update. This make sense. I shall try via different channel and come back.
But do we have any other way to manually get this configured ?
Hey
It sounds like you might have a firewall between your ssh host and github that is blocking traffic on port 22. Try from a location outside of your internal network.
Cheers,
William
I am not able to get the GIT.
git clone git@github.com:swagger-api/swagger-codegen.git
It prompts me an error
Cloning into ‘swagger-codegen’…
ssh: connect to host github.com port 22: Connection refused
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
Solved - disregard 🙂
Hello there!
I’m having a similar problem to
What I mean by response variable whose method is post:
response = self.api_client.call_api(resource_path, 'POST',
path_params,
query_params,
header_params,
body=body_params,
post_params=form_params,
files=local_var_files,
response_type='User',
auth_settings=auth_settings,
callback=params.get('callback'))
Any thoughts? Thanks!
Hey,
I still received the 404 error but the issue is resolved. You were correct it was a permission issue.
I re-looked (no pun intended) at the info from my original curl query and found the space id from the curl query was different than the space id from the front end application. I contacted the admin and the admin setup new api keys for the “right” account. Thanks for the help!
That basic syntax works for me, this worked on looker.learn.com:
curl -i -H "Authorization: token <BIG_TOKEN_HERE>" https://learn.looker.com:19999/api/3.0/looks/2938/run/json
HTTP/1.1 200 OK
Content-Type: application/json;charset=utf-8
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
Transfer-Encoding: chunked
[{"users.age_tier":"80 or Above","order_items.count":1984,"order_items.percent_total_gm":4.8631375010242754},
. . .
Are you still getting a 404?
Ok thanks for the advice.
- I can see the look in the front end (I created it).
Can you point me in the direction to run the look via curl or tell me the syntax. Below is what I have:
curl https://looker.mycompany:19999/api/3.0/looks/15133/run/csv -H "Authorization: Bearer access_token here"
Hey there
I normally see this error when I’ve made a mistake in the permissions and groups that I’ve given to the user that I am authenticating as. This can also come up when the optional arguments provided to the function are not as expected.
I’d try these two steps first:
- Sudo as the API user and make sure you can see and run the Look in the front-end application. If you can’t, then you must adjust their permissions or access so that they can find and run the Look.
- EDIT: Nevermind, data format argument is only optional for other endpoints, required for this one.
If you still can’t run the Look from the API, try authenticating and running the Look via curl
. If you can, this implies that maybe authentication is not working as expected in your Python script.
Hello,
I’m having similar issues to scottmdavidson and I am unable to run a look as I get a 404 error. See code below:
import swagger_client as looker
import os
client_id = os.environ.get('LOOKER_CLIENT_ID')
client_secret = os.environ.get('LOOKER_SECRET_KEY')
#base_url = 'https://looker.mycompany.com:9999/api/3.0/'
base_url = 'https://looker.mycompany.com:19999/api/3.0/'
unauthenticated_client = looker.ApiClient(base_url)
unauthenticated_authApi = looker.ApiAuthApi(unauthenticated_client)
token = unauthenticated_authApi.login(client_id=client_id, client_secret=client_secret)
client = looker.ApiClient(base_url, 'Authorization', 'token ' + token.access_token)
looks = looker.LookApi(client)
looks.run_look(9669,'json')
The error I receive:
ApiException: (404)
Reason: Not Found
HTTP response headers: HTTPHeaderDict({'Server': 'nginx', 'Date': 'Thu, 29 Jun 2017 19:14:36 GMT', 'Content-Type': 'application/json;charset=utf-8', 'Content-Length': '69', 'Connection': 'keep-alive', 'Vary': 'Accept-Encoding', 'X-Content-Type-Options': 'nosniff'})
HTTP response body: {"message":"Not found","documentation_url":"http://docs.looker.com/"}
I can authenticate successfully and receive a token. I tested that access_token in curl and it retrieves my user info successfully. Any help here to run a look would be great!
Reply
Enter your username or e-mail address. We'll send you an e-mail with instructions to reset your password.