GCP DataStore数据写入报错:MergeFrom参数类型不匹配问题
GCP DataStore 写入报错问题
我尝试将数据推送至GCP DataStore,以下代码片段在Jupyter Notebook中运行正常,但在VS Code中抛出错误。
代码片段
def load_data_json(self, kind_name, data_with_qp_ID, qp_id): #Load the data in JSON format to upload into the DataStore data_with_qp_ID_as_JSON = self.convert_DF_to_JSON(data_with_qp_ID, qp_id) #Loop to iterate through the JSON format and upload into the GCS Storage for data in data_with_qp_ID_as_JSON.keys(): with self.client.transaction(): incomplete_key = self.client.key(kind_name) task = datastore.Entity(key=incomplete_key) task.update(data_with_qp_ID_as_JSON[data]) self.client.put(task) return 'Ingestion Successful - Data Store Repository'
其中,Kind Name为存储桶名称,data_with_qp_id是pandas DataFrame,qp_id是该DataFrame中的列名。
报错信息
Traceback (most recent call last): File "/Users/ajaykrishnan/Desktop/Projects/Sprint 3/Data Migration/DataMigration_v1.1/main2.py", line 139, in <module> write_datastore_db.load_data_json(ds_kindname, bookmarks_data_with_qp_ID, qp_id) File "/Users/ajaykrishnan/Desktop/Projects/Sprint 3/Data Migration/DataMigration_v1.1/pkg/repository/ds_repository.py", line 50, in load_data_json self.client.put(task) File "/opt/anaconda3/lib/python3.9/site-packages/google/cloud/datastore/client.py", line 597, in put self.put_multi(entities=[entity], retry=retry, timeout=timeout) File "/opt/anaconda3/lib/python3.9/site-packages/google/cloud/datastore/client.py", line 634, in put_multi current.put(entity) File "/opt/anaconda3/lib/python3.9/site-packages/google/cloud/datastore/transaction.py", line 315, in put super(Transaction, self).put(entity) File "/opt/anaconda3/lib/python3.9/site-packages/google/cloud/datastore/batch.py", line 227, in put _assign_entity_to_pb(entity_pb, entity) File "/opt/anaconda3/lib/python3.9/site-packages/google/cloud/datastore/batch.py", line 373, in _assign_entity_to_pb bare_entity_pb = helpers.entity_to_protobuf(entity) File "/opt/anaconda3/lib/python3.9/site-packages/google/cloud/datastore/helpers.py", line 208, in entity_to_protobuf key_pb = entity.key.to_protobuf() File "/opt/anaconda3/lib/python3.9/site-packages/google/cloud/datastore/key.py", line 298, in to_protobuf key.path.append(element) TypeError: Parameter to MergeFrom() must be instance of same class: expected google.datastore.v1.Key.PathElement got PathElement.
环境信息
- Mac OS Monterey V12.06
- Python - Conda 3.9.12
内容的提问来源于stack exchange,提问作者Ajaykrishnan Selucca
相关产品推荐
相关产品推荐

