[英]Google App Engine - 401 when requesting BigQuery API
I saw some similar questions but none of them actually gives a concrete solution to this problem. 我看到了一些类似的问题,但实际上没有一个给出具体的解决方案。
The message I'm getting is this one: 我收到的消息是:
HttpError 401 when requesting https://www.googleapis.com/bigquery/v2/projects/project/queries?alt=json returned "Invalid Credentials"
Code that connects to BigQuery: 连接到BigQuery的代码:
appname = get_application_id()
project_id = appname
# Grab the application's default credentials from the environment.
credentials = GoogleCredentials.get_application_default()
# Construct the service object for interacting with the BigQuery API.
bigquery_service = build('bigquery', 'v2', credentials=credentials)
query_request = bigquery_service.jobs()
query_data = {
'query': query,
'useLegacySql': use_legacy_sql
}
query_response = query_request.query(
projectId=project_id,
body=query_data).execute()
What could be the cause(s) for this problem? 这个问题可能是什么原因?
Make sure: 确保:
GOOGLE_APPLICATION_CREDENTIALS
to point to the file created in step 1. 导出环境变量GOOGLE_APPLICATION_CREDENTIALS
以指向在步骤1中创建的文件。 Then it will work. 然后它将起作用。 More details can be found here . 可以在此处找到更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.