cisco-en-programmability / dnacentersdk

Cisco DNA Center Python SDK
https://dnacentersdk.readthedocs.io/en/latest/
MIT License
70 stars 33 forks source link

re-auth after 50 requests #72

Closed Ivanszky closed 1 year ago

Ivanszky commented 1 year ago

I have experienced that after using Sites.assign_device_to_site() 50 times with the same DNACenterAPI object, it doesn't work anymore. I suppose the authentication token might be invalidated by DNAC after 50 use?

It would be nice if DNACenterAPI would request automatically a new token once the current token becomes invalid. Alternatively it would be still nice to have a method which checks the validity of the current token and another method which would initiate a reauthentication.

As an alternative solution, splitting jobs into smaller, <50 request chunks is a feasible workaround.

fmunozmiranda commented 1 year ago

Hey @Ivanszky could you please active debug and show me more details?.

Here's detail how to bring debug on: https://dnacentersdk.readthedocs.io/en/latest/api/quickstart.html#configuring-logging-for-dnacentersdk

Thanks

zapodeanu commented 1 year ago

The Cisco DNA Center Auth token is valid for 60 minutes. Is your app running longer that 60 min?

Ivanszky commented 1 year ago

The app is running only for a couple of seconds. I will send the debugs within a couple of days.

fmunozmiranda commented 1 year ago

Hey @Ivanszky , it has been pass 29 days after your last message, please update us or we will close issue due inactivity.

Ivanszky commented 1 year ago

apologies for the late response. I've created a simple script to add dummy devices to the DNAC inventory, with IP addresses ranging from 1.1.1.0 to 1.1.1.99. The result is that only devices from 1.1.1.0 to 1.1.1.28 appeared in the inventory.

In the debug I cannot see any differences between the API communication related to successful and unsuccesful device additions. That probably means that it is not a token issue.

Meanwhile it seems that this action messed up the database/inventory service of our lab DNAC, as it was impossible to delete these 29 dummy devices through the GUI. I was able to delete them through API though.

But now I cannot delete or add normal(non-dummy) devices through the GUI either. I have restarted apic-em-inventory-manager-service, which apparently didn't fix the issue. Probably I will need to open a TAC case for this.

log_dummyDeviceAdd.txt

Ivanszky commented 1 year ago

I have opened a TAC case for this, will update this thread, as I think the root cause might be relevant for the SDK as well.

Ivanszky commented 1 year ago

it seems that I am hitting https://bst.cloudapps.cisco.com/bugsearch/bug/CSCwc11245

I am not sure if that is something which should be handled by dnacentersdk?

zapodeanu commented 1 year ago

I do not think we should handle this in the Cisco DNA Center SDK. The bug proposed work around is correct and easy to implement.

Ivanszky commented 1 year ago

The documentation mentions Automatic Rate-Limit Handling. I understand this is a different phenomenon, but one might think this is handled by the SDK (or might be totally uninformed about this issue). So maybe mentioning this bug somewhere around the Automatic Rate-Limit Handling section of the documentation can be useful for many people, before they paralyse their DNA Center for a couple of days, until TAC comes along and fixes it :)