#2021·tweepy

Oauth2 fails to authenticate

Author: javinievasCreated Nov 20, 2022Updated Apr 24, 2025

Hi,

I have the same issue that was mentioned in issue #2014. It was closed but was not solved.

After granting the app the permissions, the user is redirected to the callback url with two parameters: state and code. When passing the full URL to the fetch_token method:

fetch_token("https://mydomain.tld/mycallbackuri/?state=CfVn3zt150Z673dUu8rKLDYvX&code=QlR2VjFxVTYXXXXXXXXXXXXXXXXXMTW5rc3VXXXXXXXXXXxExLOjE2Njg5ODI3MDUyNTI6MTowOmFjOjE")

This error is returned: InvalidClientIdError: (invalid_request) Missing required parameter [code_verifier]

I was digging a bit and fount this specific line in the stacktrace:

File XXXXXXX/site-packages/tweepy/auth.py:217, in OAuth2UserHandler.fetch_token(self, authorization_response) return super().fetch_token( 218 "https://api.twitter.com/2/oauth2/token", 219 authorization_response=authorization_response, 220 auth=self.auth, 221 include_client_id=True, 222 code_verifier=self._client.code_verifier 223 )

I can see that self._client.code_verifier is passed as code_verifier, but if I check the actual value of this variable is empty.

Can't see what am I doing wrong? Or if this is an issue?