Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure cosmosdb python cosmosdb的Azure sdk属性错误_Azure Cosmosdb_Azure Sdk Python - Fatal编程技术网

Azure cosmosdb python cosmosdb的Azure sdk属性错误

Azure cosmosdb python cosmosdb的Azure sdk属性错误,azure-cosmosdb,azure-sdk-python,Azure Cosmosdb,Azure Sdk Python,我到处找了,但找不到解决这个问题的办法 我有一个azure data explorer正在运行,我想将查询结果保存到cosmodb表中 在官方文件中,他们建议使用以下代码: from azure.cosmos import CosmosClient import os url = os.environ['ACCOUNT_URI'] key = os.environ['ACCOUNT_KEY'] client = CosmosClient(url, credential=key) databas

我到处找了,但找不到解决这个问题的办法

我有一个azure data explorer正在运行,我想将查询结果保存到cosmodb表中

在官方文件中,他们建议使用以下代码:

from azure.cosmos import CosmosClient
import os

url = os.environ['ACCOUNT_URI']
key = os.environ['ACCOUNT_KEY']
client = CosmosClient(url, credential=key)
database_name = 'testDatabase'
database = client.get_database_client(database_name)
container_name = 'products'
container = database.get_container_client(container_name)

for i in range(1, 10):
    container.upsert_item({
            'id': 'item{0}'.format(i),
            'productName': 'Widget',
            'productModel': 'Model {0}'.format(i)
        }
    )

我遵循该代码并按如下方式实现:

url = 'url'
key = {'masterkey': 'my-key'}
client = CosmosClient(url, key)
database_name = 'My-database'
database = client.get_database_client(database_name)
container_name = 'My-table'
container = database.get_container_client(container_name)

for item in df:
    container.upsert_item(item)
df
是我的查询,我正在尝试将该结果推送到我的容器中

但当我运行python代码时,会出现以下错误:

Traceback (most recent call last):
  File "query.py", line 68, in <module>
    database = client.get_database_client(database_name)
AttributeError: 'CosmosClient' object has no attribute 'get_database_client'

回溯(最近一次呼叫最后一次):
文件“query.py”,第68行,在
database=client.get\u database\u client(数据库名称)
AttributeError:“CosmosClient”对象没有属性“get\u database\u client”
有什么建议说明为什么会发生这种情况吗?

找到了解决办法

在第一个配置中,我运行命令
pip install azure cosmos

但是这不起作用,所以我不得不遵循一个主题,他们建议用
--pre
运行同一个命令,因此完整的pip命令将是
pip安装--pre azure cosmos
,我天真地认为该命令将覆盖我已有的现有安装,但没有。。我不得不卸载以前的模块

pip卸载azure cosmos

然后安装--pre

现在它起作用了