HttpError:请求https://www.googleapis.com/bigquery/v2/projects/时出现< HttpError 400 [英] HttpError: <HttpError 400 when requesting https://www.googleapis.com/bigquery/v2/projects/
问题描述
以下是我在尝试对bigquery进行身份验证调用时遇到的错误dat
HttpError:< HttpError 400请求时https://www.googleapis.com/bigquery/v2/projects/ClientId/datasets/samples/tables/natality?alt=json返回无效的项目ID'ClientId'。项目ID必须包含6-63个小写字母,数字或短划线,ID必须以字母开头,不能以短划线结尾。>
这是我的main.py
导入httplib2
从google.appengine.api导入os
从google.appengine.ext导入memcache
从google.appengine导入webapp
。 ext.webapp.util导入run_wsgi_app $ b $ from oauth2client.appengine import oauth2decorator_from_clientsecrets
from bqclient import BigQueryClient
PROJECT_ID =########this是客户端ID
DATASET =samples
TABLE =natality
CLIENT_SECRETS = os.path.join(os.path.dirname(__ file__) ,
'client_secrets.json')
http = httplib2.Http(memcache)
decorator = oauth2decorator_from_clientsecrets(CLIENT_SECRETS,
'https://www.googleapis。 com / auth / bigquery')
bq = BigQueryClient(http,decorator)
class MainHandler(webapp.RequestHandler):
@ decorator.oauth_required
def get(self):
self.response.out.write(Hello Dashboard!\\\
)
modTime = bq.getLastModTime(PROJECT_ID,DATASET,TABLE)
如果modTime不是None:
msg ='Last mod time ='+ modTime
else:
msg =
self.response.out.write(msg)
application = webapp.WSGIApplication([
('/',MainHandler ),
(decorator.callback_path,decorator.callback_handler())
],debug = True)
$ b $ def main():
run_wsgi_app(application)
if __name__ =='__main__':
main()
这里是app.yaml应用程序:hellomydashboard
版本:1
运行时:python $ b
$ b api_version:1
处理程序:
- url:/favicon\.ico
static_files:favicon.ico
上传:favicon\.ico
- url:。*
script:main.py
这里是bqclient.py
impo rt httplib2
from apiclient.discovery import build $ b $ from oauth2client.appengine import oauth2decorator_from_clientsecrets
$ b $ class BigQueryClient(object):
def __init __(self,http,decorator):
创建BigQuery客户端连接
self.service = build('bigquery','v2',http = http)
self.decorator =装饰器
def getTableData(self,project,dataset,table):
decorated = self.decorator.http()
return self.service.tables().get(projectId = project,datasetId =数据集,
tableId = table).execute(修饰)
$ b $ def getLastModTime(self,project,dataset,table):
data = self.getTableData(project,dataset,table )
如果数据不是None且数据中的'lastModifiedTime':
返回数据['lastModifiedTime']
else:
返回无
def查询(self,query,project,timeout_ms = 10000):
query_config = {$ b $'query':query,
'timeoutMs':timeout_ms
}
decorated = self.decorator.http()
result_json =(self。 service.jobs()
.query(projectId = project,body = query_config)
.execute(装饰))
返回result_json
我也尝试用错误中所述的Project Id替换ClientId,但它给出了另一个错误
HttpError:当请求https://www.googleapis.com/bigquery/v2/projects/hellodashboard87/datasets/samples/tables/natality?alt=json时,< HttpError 404 Not Found:Dataset hellodashboard87:samples>
我正在关注本页的教程
https://developers.google.com/bigquery/articles/dashboard#firstcall
为了使用Google BigQuery提供的公共数据集,请使用以下参数:
项目ID : publicdata
数据集标识: samples
表ID : 为了使用您拥有的任何数据集,请将您的项目ID切换到在API控制台仪表板中找到的项目ID。 Here is the error dat i'm getting while trying to make an authentication call to bigquery Here is my main.py And here is the app.yaml And here is the bqclient.py I also tried replacing the ClientId with Project Id as said in the error but it gives another error I'm following the tutorial on this page
https://developers.google.com/bigquery/articles/dashboard#firstcall In order to use the public data sets offered by Google's BigQuery, use the following parameters: Project ID: Dataset ID: Table ID: In order to use any data sets that you own, switch your Project ID to the one found in the API Console dashboard. 这篇关于HttpError:请求https://www.googleapis.com/bigquery/v2/projects/时出现< HttpError 400的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! natality
(或任何你想使用的)
HttpError: <HttpError 400 when requesting https://www.googleapis.com/bigquery/v2/projects/ClientId/datasets/samples/tables/natality?alt=json returned "Invalid project ID 'ClientId'. Project IDs must contain 6-63 lowercase letters, digits, or dashes. IDs must start with a letter and may not end with a dash.">
import httplib2
import os
from google.appengine.api import memcache
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from oauth2client.appengine import oauth2decorator_from_clientsecrets
from bqclient import BigQueryClient
PROJECT_ID = "########" this is the Client Id
DATASET = "samples"
TABLE = "natality"
CLIENT_SECRETS = os.path.join(os.path.dirname(__file__),
'client_secrets.json')
http = httplib2.Http(memcache)
decorator = oauth2decorator_from_clientsecrets(CLIENT_SECRETS,
'https://www.googleapis.com/auth/bigquery')
bq = BigQueryClient(http, decorator)
class MainHandler(webapp.RequestHandler):
@decorator.oauth_required
def get(self):
self.response.out.write("Hello Dashboard!\n")
modTime = bq.getLastModTime(PROJECT_ID, DATASET, TABLE)
if modTime is not None:
msg = 'Last mod time = ' + modTime
else:
msg = "Could not find last modification time.\n"
self.response.out.write(msg)
application = webapp.WSGIApplication([
('/', MainHandler),
(decorator.callback_path, decorator.callback_handler())
], debug=True)
def main():
run_wsgi_app(application)
if __name__ == '__main__':
main()
application: hellomydashboard
version: 1
runtime: python
api_version: 1
handlers:
- url: /favicon\.ico
static_files: favicon.ico
upload: favicon\.ico
- url: .*
script: main.py
import httplib2
from apiclient.discovery import build
from oauth2client.appengine import oauth2decorator_from_clientsecrets
class BigQueryClient(object):
def __init__(self, http, decorator):
"""Creates the BigQuery client connection"""
self.service = build('bigquery', 'v2', http=http)
self.decorator = decorator
def getTableData(self, project, dataset, table):
decorated = self.decorator.http()
return self.service.tables().get(projectId=project, datasetId=dataset,
tableId=table).execute(decorated)
def getLastModTime(self, project, dataset, table):
data = self.getTableData(project, dataset, table)
if data is not None and 'lastModifiedTime' in data:
return data['lastModifiedTime']
else:
return None
def Query(self, query, project, timeout_ms=10000):
query_config = {
'query': query,
'timeoutMs': timeout_ms
}
decorated = self.decorator.http()
result_json = (self.service.jobs()
.query(projectId=project, body=query_config)
.execute(decorated))
return result_json
HttpError: <HttpError 404 when requesting https://www.googleapis.com/bigquery/v2/projects/hellodashboard87/datasets/samples/tables/natality?alt=json returned "Not Found: Dataset hellodashboard87:samples">
publicdata
samples
natality
(or whatever you want to use)