简体   繁体   English

Google App Engine-要求BigQuery API时显示401

[英]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: 确保:

  1. You've created a service account with the correct IAM roles assigned. 您已经为服务帐户分配了正确的IAM角色。
  2. Exported the environment variable 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.

相关问题 App Engine上带有Google Slides API和OAuth2的HTTPError 401 - HTTPError 401 with Google Slides API & OAuth2 on App Engine 401 请求 Bing Text to Speech API 时未经授权 - 401 Unauthorized when requesting Bing Text to Speech API 在Google App Engine开发服务器上访问BigQuery - Accessing BigQuery on Google App Engine dev server 适用于Google App Engine数据存储区到BigQuery进程的UnicodeEncodeError - UnicodeEncodeError for Google App Engine Datastore to BigQuery process WooCommerce API在Google App Engine中提供了401,但在本地环境中可以正常运行(200 OK) - WooCommerce API gives 401 in Google App Engine but works (200 OK) in local env Google云端存储&lt;-&gt; Google App Engine-&gt; Google BigQuery - Google Cloud Storage <-> Google App Engine -> Google BigQuery 尝试将Google App Engine中的insertAll用于BigQuery时出现HTTP 501错误 - HTTP 501 error when trying to use insertAll from Google App Engine to BigQuery 使用Gmail API和Google App-Engine时的身份验证 - Authentication when using Gmail API and Google App-Engine 从Google App Engine调用Reddit api时出现错误429 - Error 429 when invoking Reddit api from Google App Engine Google App Engine日历API - Google app engine Calendar API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM