{'status': 401, 'message': 'invalid csrf token'} When trying to authorize through Python Script

Send as in redirect (for clarity)

But the whole construct of the URL is wrong here

So you need to go back to the docs and check you are doing things correctly. Or we need to see all your code to try to understand what you are trying to do here.