我在运行以下代码时遇到了问题:
from google.cloud import bigquery
client = bigquery.Client.from_service_account_json(BQJSONKEY,project = BQPROJECT)
dataset = client.dataset(BQDATASET)
assert not dataset.exists()
弹出以下错误:'DatasetReference' object has no attribute 'exists'
同样,当我这样做的时候:
table = dataset.table(BQTABLE)
我明白了:'TableReference' object has no attribute 'exists'
然而,根据文档,它应该可以工作:https://googlecloudplatform.github.io/google-cloud-python/stable/bigquery/usage.html#datasets
这是我的云(google- pip freeze
的一部分):
gapic-google-cloud-datastore-v1==0.15.3
gapic-google-cloud-error-reporting-v1beta1==0.15.3
gapic-google-cloud-logging-v2==0.91.3
gevent==1.2.2
glob2==0.5
gmpy2==2.0.8
google-api-core==0.1.1
google-auth==1.2.1
google-cloud==0.30.0
google-cloud-bigquery==0.28.0
google-cloud-bigtable==0.28.1
google-cloud-core==0.28.0
google-cloud-datastore==1.4.0
google-cloud-dns==0.28.0
google-cloud-error-reporting==0.28.0
google-cloud-firestore==0.28.0
google-cloud-language==1.0.0
google-cloud-logging==1.4.0
google-cloud-monitoring==0.28.0
google-cloud-pubsub==0.29.1
google-cloud-resource-manager==0.28.0
google-cloud-runtimeconfig==0.28.0
google-cloud-spanner==0.29.0
google-cloud-speech==0.30.0
google-cloud-storage==1.6.0
google-cloud-trace==0.16.0
google-cloud-translate==1.3.0
google-cloud-videointelligence==0.28.0
google-cloud-vision==0.28.0
google-gax==0.15.16
google-resumable-media==0.3.1
googleapis-common-protos==1.5.3
我想知道如何才能修复它并使其正常工作?
发布于 2017-11-29 01:29:35
不确定您是如何获得此文档的,但您应该将以下内容作为参考:
https://googlecloudplatform.github.io/google-cloud-python/latest/bigquery/usage.html#datasets
0.28
的代码应该类似于:
dataset_refence = client.dataset(BQDATASET)
dataset = client.get_dataset(dataset_reference)
assert dataset.created is not None
发布于 2017-11-29 01:16:12
我想您在调用exists()
之前忘记了创建数据集
dataset = client.dataset(BQDATASET)
dataset.create()
assert not dataset.exists()
https://stackoverflow.com/questions/47537278
复制相似问题