Using Python to connect to cosmosDB throws Authorization header doesn't confirm to the required format
Closed this issue · 2 comments
webcluster4u commented
Hi,
I am facing some issue when I use your library to connect to my cosmosDB in python3.7. I have setup a private cosmosDB database and it has a private endpoint in my private subnet. I use one VM i the private subnet to run below python codes.
>>> import azure.cosmos.cosmos_client as cosmos_client
import azure.cosmos.errors as errors
import azure.cosmos.http_constants as http_constants
>>> >>> >>> import os
>>> client = cosmos_client.CosmosClient('https://thermo-breast-cancer-cosmos-account.table.cosmos.azure.com:443', 'KrZklvMYWBcIaujH2APJES8eAsjCZDaUSyVNec6VUi28aeUWwn4io48aFPqlyuYFnhtXq3hlPzhZIuUQ4tCaww==')
>>> for z in client.list_databases():
... print(z)
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/azure/core/paging.py", line 122, in __next__
return next(self._page_iterator)
File "/usr/local/lib/python3.7/site-packages/azure/core/paging.py", line 74, in __next__
self._response = self._get_next(self.continuation_token)
File "/usr/local/lib/python3.7/site-packages/azure/cosmos/_query_iterable.py", line 98, in _fetch_next
block = self._ex_context.fetch_next_block()
File "/usr/local/lib/python3.7/site-packages/azure/cosmos/_execution_context/execution_dispatcher.py", line 110, in fetch_next_block
raise e
File "/usr/local/lib/python3.7/site-packages/azure/cosmos/_execution_context/execution_dispatcher.py", line 102, in fetch_next_block
return self._execution_context.fetch_next_block()
File "/usr/local/lib/python3.7/site-packages/azure/cosmos/_execution_context/base_execution_context.py", line 75, in fetch_next_block
return self._fetch_next_block()
File "/usr/local/lib/python3.7/site-packages/azure/cosmos/_execution_context/base_execution_context.py", line 163, in _fetch_next_block
return self._fetch_items_helper_with_retries(self._fetch_function)
File "/usr/local/lib/python3.7/site-packages/azure/cosmos/_execution_context/base_execution_context.py", line 135, in _fetch_items_helper_with_retries
return _retry_utility.Execute(self._client, self._client._global_endpoint_manager, callback)
File "/usr/local/lib/python3.7/site-packages/azure/cosmos/_retry_utility.py", line 75, in Execute
result = ExecuteFunction(function, *args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/azure/cosmos/_retry_utility.py", line 130, in ExecuteFunction
return function(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/azure/cosmos/_execution_context/base_execution_context.py", line 133, in callback
return self._fetch_items_helper_no_retries(fetch_function)
File "/usr/local/lib/python3.7/site-packages/azure/cosmos/_execution_context/base_execution_context.py", line 116, in _fetch_items_helper_no_retries
(fetched_items, response_headers) = fetch_function(self._options)
File "/usr/local/lib/python3.7/site-packages/azure/cosmos/_cosmos_client_connection.py", line 344, in fetch_fn
lambda _, b: b, query, options, **kwargs
File "/usr/local/lib/python3.7/site-packages/azure/cosmos/_cosmos_client_connection.py", line 2385, in __QueryFeed
result, self.last_response_headers = self.__Get(path, request_params, headers, **kwargs)
File "/usr/local/lib/python3.7/site-packages/azure/cosmos/_cosmos_client_connection.py", line 2217, in __Get
**kwargs
File "/usr/local/lib/python3.7/site-packages/azure/cosmos/_synchronized_request.py", line 218, in SynchronizedRequest
**kwargs
File "/usr/local/lib/python3.7/site-packages/azure/cosmos/_retry_utility.py", line 73, in Execute
result = ExecuteFunction(function, global_endpoint_manager, *args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/azure/cosmos/_retry_utility.py", line 130, in ExecuteFunction
return function(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/azure/cosmos/_synchronized_request.py", line 158, in _Request
raise exceptions.CosmosHttpResponseError(message=data, response=response)
azure.cosmos.exceptions.CosmosHttpResponseError: Status code: 401
{"odata.error":{"code":"Unauthorized","message":{"lang":"en-us","value":"Authorization header doesn't confirm to the required format. Please verify and try again.\r\nActivityId: a0610060-e318-4b68-b08d-362f71671963, documentdb-dotnet-sdk/2.11.0 Host/64-bit MicrosoftWindowsNT/6.2.9200.0\nRequestID:a0610060-e318-4b68-b08d-362f71671963\n"}}}
As you see , it gives me some error regrading mismatch hear authorization. Perhaps, I need to tweek the codes but I do not know how to fix this error?
Any help would be appreciated.
southpolesteve commented
Duplicate of Azure/azure-sdk-for-python#13225
webcluster4u commented
Hi Steve,
This issue has been resolved for me so you may close or delete the threads.
Thanks,
Mahdi
From: Steve Faulkner
Sent: Thursday, 20 August 2020 6:54 AM
To: Azure/azure-cosmos-python
Cc: Bazarganigilani; Author
Subject: Re: [Azure/azure-cosmos-python] Using Python to connect to cosmosDBthrows Authorization header doesn't confirm to the required format (#203)
Duplicate of Azure/azure-sdk-for-python#13225
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.