Skip to content

Commit 6fd655f

Browse files
authored
Merge pull request #768 from crowdsecurity/fix/sdk-doc
fix(sdk-python): fix sapi sdk doc
2 parents 1e2ce7d + bb3dbca commit 6fd655f

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

  • crowdsec-docs/unversioned/service_api/sdks

crowdsec-docs/unversioned/service_api/sdks/python.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ After obtaining an API key, you can authenticate requests to the Service API by
3838
import os
3939
from crowdsec_service_api import (
4040
Server,
41+
Info
4142
ApiKeyAuth,
4243
)
4344

4445
KEY = os.getenv('KEY')
4546

4647
auth = ApiKeyAuth(api_key=KEY)
47-
client = Blocklists(base_url=Server.production_server.value, auth=auth)
48+
client = Info(base_url=Server.production_server.value, auth=auth)
4849
# Get info about the user
4950
response = client.get_info()
5051
print(response)
@@ -91,6 +92,7 @@ from crowdsec_service_api import (
9192
Server,
9293
ApiKeyAuth,
9394
)
95+
from httpx import HTTPStatusError
9496

9597
KEY = os.getenv('KEY')
9698

@@ -104,8 +106,15 @@ try:
104106
size=50,
105107
)
106108
print(response)
109+
except HTTPStatusError as e:
110+
if e.response.status_code == 401:
111+
print("Unauthorized: Invalid API key")
112+
elif e.response.status_code == 409:
113+
print("Conflict", e.response.json())
114+
else:
115+
print(f"An error occurred: {e}")
107116
except Exception as e:
108-
print(f"An error occurred: {e}")
117+
print(f"Another error occurred: {e}")
109118
```
110119

111120
### Support

0 commit comments

Comments
 (0)