toggl / toggl_api_docs

Documentation for the Toggl API
1.39k stars 235 forks source link

Problems with urllib in Python #408

Closed BANOnotIT closed 2 years ago

BANOnotIT commented 3 years ago

Problem

Even if you add a password manager to urllib opener as it is stated in documentation, you'll get 403 error

It breaks because of not implemented 401 status. urllib tries an unauthorized request first and only if it respond with 401 status it tries an authorized one. But Toggl API responds with 403 status on unauthorized requests (#339)

Solution

Use HTTPPasswordMgrWithPriorAuth and set authorized status at the start

password_mgr = urllib.request.HTTPPasswordMgrWithPriorAuth()

password_mgr.add_password(None, 'https://api.track.toggl.com/', user, passwd)
password_mgr.update_authenticated('https://api.track.toggl.com/', True)  # this skips unauthorized request
joeriharleman commented 2 years ago

Hello @BANOnotIT!

Thank you for submitting your issue. Unfortunately this repository is largely unmaintained, which means issues remain unseen and do not get dealt with in a respectable manner. We're sorry for not getting back to you sooner.

This issue has been around for a long time so we will close it for now, but please let our excellent 24/5 support staff know you if you have any unresolved issues with our platform, documentation or APIs. They're also really good at noting down feature requests for our development teams. Please find them on our support page by clicking the little icon in the bottom right corner of the screen.

Kind regards, Joeri from Toggl