【发布时间】:2019-11-24 20:49:48
【问题描述】:
我想使用 python 脚本将包含 json 对象列表的 .json 文件上传到 Azure CosmosDB。
我指的是以下链接https://github.com/Azure-Samples/azure-cosmos-db-python-getting-started 用于上传包含 JSON 对象列表的 json 文件。此处使用的 Azure cosmos 客户端库仅支持一次发送一个 json 对象,但我想在单个请求中发送一个 json 对象列表。
这是我要发送的json格式
[{
'id': 'server1',
'Web Site': 0,
'Cloud Service': 0,
'Virtual Machine': 0,
'message': 'Hello World from Server 1!'
},
{
'id': 'server2',
'Web Site': 0,
'Cloud Service': 0,
'Virtual Machine': 0,
'message': 'Hello World from Server 1!'
}]
这是我得到的错误
nayana@nayana-HP-Notebook:~/Azure$ python3 Upload\ to\ azure\ cosmo.py
Traceback (most recent call last):
File "Upload to azure cosmo.py", line 52, in <module>
'message': 'Hello World from Server 2!'
File "/usr/local/lib/python3.5/dist-packages/azure/cosmos/cosmos_client.py", line 1023, in CreateItem
collection_id, document, path = self._GetContainerIdWithPathForItem(database_or_Container_link, document, options)
File "/usr/local/lib/python3.5/dist-packages/azure/cosmos/cosmos_client.py", line 1080, in _GetContainerIdWithPathForItem
CosmosClient.__ValidateResource(document)
File "/usr/local/lib/python3.5/dist-packages/azure/cosmos/cosmos_client.py", line 2854, in __ValidateResource
id = resource.get('id')
AttributeError: 'list' object has no attribute 'get'
我使用 pip3 install azure-cosmos 安装了 azure-cosmos 包,其中包含 cosmos_client.py
【问题讨论】:
-
您好,我的回答对您有帮助吗?
标签: json azure azure-cosmosdb