DeprecationWarning: The 'access_token' params are deprecated. Use 'bearer_auth_credentials' param instead

Hi,
I was using the square python SDK, and using the access token for authentication gave me a DeprecationWarning. I was trying to use the personal access token as the script will run on the server without the manual intervention.

How do I resolve this error.

Here is the error details: DeprecationWarning: The ‘access_token’ params are deprecated. Use ‘bearer_auth_credentials’ param instead.

This is the code snippet I am using for authentication:

square_client = Client(
environment=“sandbox”,
access_token=sandbox_access_token
)

I got the answer to this.

Just had to use BearerAuthCredentials class for access token.

Code:

bearer_auth_credential = BearerAuthCredentials(
access_token=sandbox_access_token
)
square_client = Client(
environment=“sandbox”,
bearer_auth_credentials=bearer_auth_credential
)

Yep, that’s it! Glad you were able to figure it out. :slightly_smiling_face:

This is very helpful!

Could you provide the import statement needed for the BearerAuthCredentials constructor?

Many thanks for bearing with me!

The BearerAuthCredentials class is available in o_auth_2.py
Use the following import:

from square.http.auth.o_auth_2 import BearerAuthCredentials

1 Like