我正在尝试使用云函数将数据插入到云扳手表中,但它抛出了下面给出的错误。从云扳手读取数据工作正常,但使用数据定义语言命令和 batch.insert 方法写入都会引发相同的错误。我在想它的某种权限问题!我不知道怎么解决?需求文件只包含 google-cloud-spanner==1.7.1在云函数中运行的代码import jsonfrom google.cloud import spannerINSTANCE_ID = 'AARISTA'DATABASE_ID = 'main'TABLE_NAME = 'userinfo'dataDict = Nonedef new_user(request): dataDict = json.loads(request.data)# Data is available in dict format if dataDict['USER_ID']==None: return "User id empty" elif dataDict['IMEI'] == None: return "Imei number empty" elif dataDict['DEVICE_ID'] == None: return "Device ID empty" elif dataDict['NAME'] == None: return "Name field is empty" elif dataDict['VIRTUAL_PRIVATE_KEY']== None: return "User's private key cant be empty" else: return insert_data(INSTANCE_ID,DATABASE_ID)def insert_data(instance_id, database_id): spanner_client = spanner.Client() instance = spanner_client.instance(instance_id) database = instance.database(database_id) def insert_user(transcation): row_ct= transcation.execute_update("INSERT userinfo (USER_ID,DEVICE_ID,IMEI,NAME,VIRTUAL_PRIVATE_KEY) VALUES" "("+dataDict['USER_ID']+', '+dataDict['DEVICE_ID']+', '+ dataDict['IMEI']+', '+dataDict['NAME']+', '+dataDict['VIRTUAL_PRIVATE_KEY']+")") database.run_in_transaction(insert_user) return 'Inserted data.'
添加回答
举报
0/150
提交
取消