python - BigQuery 无效的数据集 ID

标签 python google-bigquery


我曾经在 UI 中查询
这次,我在 cloud shell 中,并尝试通过 python 访问我的数据集和表

from google.cloud import bigquery

client = bigquery.Client()
dataset_id = 'mytest-0001:reports_test'
table_id = 'test_data'
dataset_ref = client.dataset(dataset_id)
dataset = client.get_dataset(dataset_ref)
table_ref = dataset_ref.table(table_id)
table = client.get_table(table_ref)
print('Dataset ID: '.format(dataset_id))
print('Description: '.format(dataset.description))
print(table.schema)
print(table.description)
print(table.num_rows)

我在下面遇到了一些错误...

google.api_core.exceptions.BadRequest: 400 GET https://www.googleapis.com/bigquery/v2/projects/gcd-my-reporting/datasets/mytest-0001:reports_test: Invalid dataset ID "mytest-0001:reports_test". Dataset IDs must be al phanumeric (plus underscores, dashes, and colons) and must be at most 1024 characters long.

由于某些原因我无法修改数据集 ID,有什么办法可以解决这个问题吗?

最佳答案

您不必修改dataset id,只需指定dataset id,而不指定project id。如果您出于任何原因想要指定项目,则必须在定义 client 时执行此操作,如 this document 中所述。 .

代码将是:

from google.cloud import bigquery

client = bigquery.Client(project='mytest-0001')
dataset_id = 'reports_test'

关于python - BigQuery 无效的数据集 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50322750/

相关文章:

python - anaconda 和点云库

google-bigquery - 如何让 Google BigQuery 正确检测标题名称?

google-bigquery - 奇怪的问题: Bigquery dataset not found

go - 使用 goavro 创建的 Avro 文件将数字数据加载到 BigQuery

google-bigquery - BigQuery 新数据类型 DATE

google-bigquery - 是否可以使用服务帐户在 BigQuery "Schedule Query"功能中安排查询?

python - 如何将多条曲线拟合到单个数据散点图?

Python:从列表中解析只打印最后一项,而不是全部?

python - keras模型加载错误

python - 为什么python中有的包或函数首字母大写,有的不大写?