我在尝试将 Looker SDK 与 Python 结合使用时遇到一些问题。
按照本教程中的步骤进行操作https://colab.research.google.com/github/looker-open-source/sdk-codegen/blob/main/python/python-sdk-tutorial.ipynb 我就是无法执行步骤 2。
try:
response = sdk.run_look(
look_id=look.id,
result_format= "json" # Options here are csv, json, json_detail, txt, html, md, xlsx, sql (returns the raw query), png, jpg. JSON is the easiest to work with in python, so we return it.
)
data = json.loads(response) #The response is just a string, so we have to use the json library to load it as a json dict.
print(data) #If our query was successful we should see an array of rows.
except:
raise Exception(f'Error running look {look.id}')
当我尝试运行此代码时,出现错误
异常:运行查找时出错 1234
当我尝试使用
run_query()
方法时,也会发生同样的情况。有谁知道它可能是什么?
try:
response = sdk.run_query(
query_id=explore_query.id,
result_format= "sql" # Options here are csv, json, json_detail, txt, html, md, xlsx, sql (returns the raw query), png, jpg. JSON is the easiest to work with in python, so we return it.
)
print(response) #If our query was successful we should see an array of rows.
except:
raise Exception(f'Error running query {explore_query.id}')
问题解决了。发生此问题的原因是,当仪表板仅存在于开发人员上时,SDK 默认设置为生产环境。
执行以下行将 sdk 设置为 dev:
sdk.update_session(body = models.WriteApiSession(workspace_id =“dev”))
下面这个是设置到特定的分支:
sdk.update_git_branch(project_id="meli_lookerhub", body=mdls.WriteGitBranch(name="branch_name"))
其中project_id是您正在使用的项目,name是您指定的分支名称。
按照以下步骤,问题就解决了,一切都运行良好。