File tree Expand file tree Collapse file tree
crowdsec-docs/unversioned/service_api/sdks Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,13 +38,14 @@ After obtaining an API key, you can authenticate requests to the Service API by
3838import os
3939from crowdsec_service_api import (
4040 Server,
41+ Info
4142 ApiKeyAuth,
4243)
4344
4445KEY = os.getenv(' KEY' )
4546
4647auth = 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
4950response = client.get_info()
5051print (response)
@@ -91,6 +92,7 @@ from crowdsec_service_api import (
9192 Server,
9293 ApiKeyAuth,
9394)
95+ from httpx import HTTPStatusError
9496
9597KEY = 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} " )
107116except Exception as e:
108- print (f " An error occurred: { e} " )
117+ print (f " Another error occurred: { e} " )
109118```
110119
111120### Support
You can’t perform that action at this time.
0 commit comments