Can't get the cosmos client to work - any ideas?

This issue has been created since 2019-12-17.

When I try to import the Cosmos DB client I get the following error:

"from azure.cosmos import CosmosClient, PartitionKey, exceptions

ImportError: cannot import name 'CosmosClient' from 'azure.cosmos' (C:\Users\markl\AppData\Local\Programs\Python\Python37-32\lib\site-packages\azure\"

I have installed azure-cosmos, I am running Python 3.7.

Any help much appreciated.

benperk wrote this answer on 2020-01-10

I had the same issue but was targeting 2.7.16. I uninstalled that and targeted 3.8.0.


I executed:

python -m venv .venv
pip install --pre azure-cosmos

Also, I found the variable "endpoint" had "" and not '' which I changed, don't know if that matters but it's different and didn't test it, just wanted to mention JIC. But most importantly, execution failed when I left the default values for endpoint and key. Meaning, a real Cosmos DB endpoint and a real Cosmos DB key are required for it to compile …until then it fails with:

File ".\", line 11, in
client = CosmosClient('endpoint', 'key')

binascii.Error: Incorrect padding


tolgadur wrote this answer on 2020-01-27

same problem here

ghousethanedar wrote this answer on 2020-02-28

Same problem.....
Did you get any solution for this?

benperk wrote this answer on 2020-03-02

If you are getting the same exception as I provided in the previous post, then this is what resolved it for me: "a real Cosmos DB endpoint and a real Cosmos DB key are required for it to compile".

I did get it to work, yes.

endpoint = ''


DukaJ wrote this answer on 2020-03-22

Same problem here, anyone?

gbonventre wrote this answer on 2020-03-25

@DukaJ Try passing in the key as a dictionary
key = {'masterKey': 'some_key_here_as_string'}

meigaoms wrote this answer on 2020-04-12

same problem here. Anyone got a solution?

jyoo wrote this answer on 2020-04-17

Have you checked the version of azure-cosmos? If you installed the SDK by pip install azure-cosmos without --pre, the SDK version would be 3.1.2, and you would encounter the error.

Check its version by pip list, and make sure if there is azure-cosmos 4.0.0b6. If there is not, pip uninstall azure-cosmos and run pip install --pre azure-cosmos

wadzaw wrote this answer on 2020-05-01

@jyoo 's suggestion (adding --pre to pip install) does work.

But here's a workaround with the 3.x.x version :
from azure.cosmos.cosmos_client import CosmosClient
from azure.cosmos.partition_key import PartitionKey

ChrisMiller-SQ wrote this answer on 2021-01-22

I think if you have the azure-cli installed it's written in python. So it installs an out-of-date version of the azure.cosmos package, which you also can't remove with pip3 uninstall, because it's in the python library path, but not in the location that pip3 uninstall will remove from.

After you get yourself authenticated with azure, uninstalling the azure-cli (apt-get uninstall azure-cli, apt-get autoremove, and the autoremove is not negotiable), then you can use pip to install azure and everything will be fine.

More Details About Repo
Owner Name Azure-Samples
Repo Name azure-cosmos-db-python-getting-started
Full Name Azure-Samples/azure-cosmos-db-python-getting-started
Language Python
Created Date 2017-05-10
Updated Date 2021-09-17
Star Count 34
Watcher Count 40
Fork Count 43
Issue Count 4


Issue Title Created Date Comment Count Updated Date
Add message to v1 that users should update to v2 1 2021-03-10 2022-08-07
Add back (singular) registry-path output 1 2021-02-21 2022-07-26
[BUG] v2.4 breaks pushing multiple tags at once 6 2021-11-14 2022-05-08
Add a GHCR example and document it 1 2021-09-09 2022-08-01
Could you Explain some things 1 2021-05-30 2022-07-30 1 2021-05-15 2022-07-20
Idk but its not working 0 2022-02-16 2022-07-30
Rat,not working,shit gen . 2 2022-02-16 2022-02-15
Make program asynchronous 1 2022-02-21 2022-07-30
Frame based navigation OnActivateAsync and exceptions 3 2021-05-10 2022-08-05
Abbility to update cached data without deleting whole cache 1 2021-06-08 2022-07-30
How do you implement your dropout method in unsupervised setting? And do you apply any dropout in the supervised setting? 1 2021-11-30 2022-08-01
Is there any class imbalance problem in loss calculation ? 3 2021-12-20 2022-08-01
Can't make a vertical draggable slider without set number if slider so scroll 0 2021-01-19 2022-07-26
Allow hiding git ignored files/directories 1 2021-04-16 2022-08-05
Generators should not generate .txt.slim templates 0 2022-01-03 2022-07-20
Unable to destroy `awscc_ec2_vpc` if tags set to empty list 0 2022-02-22 2022-07-31
[BUG]new Feat: 支付测试时除余额支付以外,其他的支付方式会卡在正在处理,无法跳转 14 2022-05-11 2022-08-06
Add Gradient function for ReLU 0 2021-06-12 2022-08-06
"Run Dialyzer" step on CI might be doing nothing 1 2022-02-19 2022-08-12
The OC binary downloaded via the web console is very old 1 2021-07-01 2022-07-24
The package integrity check failed for almost all Microsoft packages I have tried to install 2 2022-04-02 2022-07-30
Stackstorm-ha on Kubernetes with openstack Magnum 2 2021-01-25 2022-07-30
Featured Azure Products links 3 2021-08-03 2022-08-11
[tanzuobservabilityexporter] Enhance accuracy of exponential delta histograms when sending to wavefront 2 2022-07-07 2022-08-10
Duplicated span while instrumenting a Quarkus gRPC server 0 2022-07-21 2022-08-05
Disable update check on startup 8 2021-10-13 2022-07-24
Export Filmstrip as Image is obscured by the filmstrip 0 2021-03-22 2022-07-22
Expose more details of payloads in Sentry reports 1 2021-08-28 2022-07-30
Enhancements to support BS 5.x (and 4.x/3.x) 0 2021-05-20 2022-08-11
Passive JA3/JA3S fingerpint via libpcap 0 2022-07-13 2022-08-12
Add flag validation for host discovery 0 2022-07-04 2022-07-28
Download Wifi / Mobile Data very slow 1 2022-07-12 2022-08-02
Support 7-zip on non-Windows platforms 0 2021-06-07 2022-07-28
website example cannot accessed 17 2021-09-13 2022-08-05
GeoJson overlay flickers when using Raster tiles 4 2021-07-15 2022-07-16
C# type safety when passing collections across the api surface 0 2021-10-11 2022-08-06
Feature name missing from Change Request page 4 2022-05-03 2022-07-28
Update the default eslint configuration to ignore config and dist files 1 2022-03-09 2022-07-21
bootstrap script does not work, uses wrong URL 1 2021-09-28 2022-08-01
Issue on displayport digital audio output 1 2022-01-14 2022-08-11
[BUG] Possible cuda context problem in mpirun/horovodrun 0 2022-01-04 2022-08-01
Convert string lambda expression with anonymous type 2 2022-04-16 2022-07-31
Unable to transfer/perform deep linking with more than 100Kb data using Linking.OpenUrl 2 2021-12-06 2022-08-12
When tests fail during `[email protected]` the step does not emit failure exit code 0 2022-07-21 2022-08-12
The sample which fetches the value of Esim EID 0 2021-12-09 2022-08-05
Continous speech recognition 1 2021-12-17 2022-08-05
Expose API about the VS Code version of the currently running instance. 5 2021-12-22 2022-08-07
logging code seems missing 0 2021-10-08 2022-07-02