我撰寫了以下 python 函式(完整代碼的片段)以在 AWS Lambda 中作業。它的目的是從 S3 存盤桶中獲取 GeoJSON 并相應地決議它。
決議后,將其放回 JSON 格式 ( data),然后應使用
bulk_item['uuid'] = str(uuid.uuid4())
bulk_item['name'] = feature_name
bulk_item['type'] = feature_type
bulk_item['info'] = obj
bulk_item['created'] = epoch_time
bulk_item['scope'] = 2
data = json.dumps(bulk_item)
print(data)
self.database.upsert_record(self.organisation, json_doc=data)
except Exception as e:
print(f'Exception: {e.__class__.__name__}({e})')
與上述相關的 db_access 檔案是另一個 python 腳本。功能upsert_record如下:
def upsert_record(self, organisation,
json_doc={}):
在我嘗試將其插入資料庫之前,我的代碼運行良好。一旦到達這條線,它就會拋出錯誤
Traceback (most recent call last):
File "/var/task/s3_asset_handler.py", line 187, in process_incoming_file
self.database.upsert_record(self.organisation, json_doc=data)
File "/opt/python/database_access.py", line 1218, in upsert_record
new_uuid = json_doc['uuid']
TypeError: string indices must be integers
我似乎根本無法弄清楚這個問題
uj5u.com熱心網友回復:
您試圖從 JSON 物件中獲取元素,但傳遞了一個字串。
這
data = json.dumps(bulk_item)
創建一個表示物件的字串。
嘗試單獨使用bulk_item。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/426235.html
下一篇:帶有字串引數的一般例外
