Skip to content

Commit 9054665

Browse files
Merge pull request #220558 from seesharprun/cosmos-fix-ru-python-samples
Cosmos DB | Bug fix python RU lookup sample
2 parents 6d93390 + 33ddd32 commit 9054665

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

articles/cosmos-db/nosql/find-request-unit-charge.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,16 +152,26 @@ For more information, see [Quickstart: Build a Node.js app by using an Azure Cos
152152

153153
## Use the Python SDK
154154

155-
The `CosmosClient` object from the [Python SDK](https://pypi.org/project/azure-cosmos/) exposes a `last_response_headers` dictionary that maps all the headers returned by the underlying HTTP API for the last operation executed. The request charge is available under the `x-ms-request-charge` key:
155+
The `Container` object from the [Python SDK](https://pypi.org/project/azure-cosmos/) exposes a `last_response_headers` dictionary that maps all the headers returned by the underlying HTTP API for the last operation executed. The request charge is available under the `x-ms-request-charge` key:
156156

157157
```python
158-
response = client.ReadItem(
159-
'dbs/database/colls/container/docs/itemId', {'partitionKey': 'partitionKey'})
160-
request_charge = client.last_response_headers['x-ms-request-charge']
158+
new_item = {
159+
"id": "70b63682-b93a-4c77-aad2-65501347265f",
160+
"partition_key": "61dba35b-4f02-45c5-b648-c6badc0cbd79",
161+
"name": "Yamba Surfboard"
162+
}
163+
container.create_item(new_item)
164+
165+
request_charge = container.client_connection.last_response_headers["x-ms-request-charge"]
166+
```
167+
168+
```python
169+
existing_item = container.read_item(
170+
item="70b63682-b93a-4c77-aad2-65501347265f"
171+
partition_key="61dba35b-4f02-45c5-b648-c6badc0cbd79"
172+
)
161173

162-
response = client.ExecuteStoredProcedure(
163-
'dbs/database/colls/container/sprocs/storedProcedureId', None, {'partitionKey': 'partitionKey'})
164-
request_charge = client.last_response_headers['x-ms-request-charge']
174+
request_charge = container.client_connection.last_response_headers["x-ms-request-charge"]
165175
```
166176

167177
For more information, see [Quickstart: Build a Python app by using an Azure Cosmos DB for NoSQL account](quickstart-python.md).

0 commit comments

Comments
 (0)