python 中的 Web 服务在 Big Query 中获取 table 的架构信息

Web service in python to get the schema information of table in Big Query

我在 python 中编写了一个 Web 服务来接受 DatasetName 和 TableName 作为 url 中的输入,它们将被传递给大查询,字段将作为输出返回。

我已经使用 python 客户端进行 bigquery 并像这样访问架构信息,但无法获得我预期的结果。

it returns "Invalid dataset ID "publicdata:samples"。数据集 ID 必须是字母数字(加上下划线、破折号和冒号),并且长度最多为 1024 个字符。" >"

import web
from bigquery import get_client
urls = (
    '/GetFields(.*)', 'get_Fields'

)
app = web.application(urls, globals())
class get_Fields:
    def GET(self,r):
          datasetname = web.input().datasetName
          tablename = web.input().tableName
# BigQuery project id as listed in the Google Developers Console.
          project_id = 'din-1085'
# Service account email address as listed in the Google Developers Console.
          service_account = '101363222700-epqo6lmkl67j6u1qafha9dke0pmcck3@developer.gserviceaccount.com'
# PKCS12 or PEM key provided by Google.
          key = 'Digin-d2421e7da9.p12'
          client = get_client(project_id, service_account=service_account,
                            private_key_file=key, readonly=True)
        # Submit an async query.
          job_id, _results = client.get_table_schema(datasetname,tablename)

        # Retrieve the results.         
          return results
if  __name__ == "__main__":
    app.run()

这是我传递的数据:

http://localhost:8080/GetFields?datasetName=publicdata:samples&tableName=shakespeare

数据集名称:publicdata:samples 表名 : 莎士比亚

预期输出:

字数
word_count
语料库
corpus_date

终于通过更改此行使其工作

发件人:

# Submit an async query.
          job_id, _results = client.get_table_schema(datasetname,tablename)

收件人:

# Submit an async query.
      results = client.get_table_schema(datasetname,tablename)