[GH-ISSUE #647] TypeError: __init__() got an unexpected keyword argument 'allowed_methods' #386

Open
opened 2026-02-27 23:22:20 +03:00 by kerem · 23 comments
Owner

Originally created by @marcswan on GitHub (Feb 28, 2021).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/647

Hi, i started to get this error after update. Month ago it worked perfectly fine. I am new to python so maybe i am doing something wrong.

import spotipy as sp
from spotipy.oauth2 import SpotifyClientCredentials
import pandas as pd

client_id = "my_client_id"
client_secret = "my_client_secret"

client_credentials_manager = SpotifyClientCredentials(client_id,client_secret)
sp = spotipy.Spotify(client_credentials_manager = client_credentials_manager)

And I get this response

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-4-85ea47b59519> in <module>
      3 
      4 client_credentials_manager = SpotifyClientCredentials(client_id,client_secret)
----> 5 sp = spotipy.Spotify(client_credentials_manager = client_credentials_manager)

~\AppData\Roaming\Python\Python38\site-packages\spotipy\client.py in __init__(self, auth, requests_session, client_credentials_manager, oauth_manager, auth_manager, proxies, requests_timeout, status_forcelist, retries, status_retries, backoff_factor, language)
    164         else:
    165             if requests_session:  # Build a new session.
--> 166                 self._build_session()
    167             else:  # Use the Requests API module as a "session".
    168                 self._session = requests.api

~\AppData\Roaming\Python\Python38\site-packages\spotipy\client.py in _build_session(self)
    191     def _build_session(self):
    192         self._session = requests.Session()
--> 193         retry = urllib3.Retry(
    194             total=self.retries,
    195             connect=None,

TypeError: __init__() got an unexpected keyword argument 'allowed_methods'

When I changed it to this as in docs
sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials(client_id = 'my_client_id', client_secret = 'my_client_secret'))
i still have the same error.

Originally created by @marcswan on GitHub (Feb 28, 2021). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/647 Hi, i started to get this error after update. Month ago it worked perfectly fine. I am new to python so maybe i am doing something wrong. ``` import spotipy as sp from spotipy.oauth2 import SpotifyClientCredentials import pandas as pd client_id = "my_client_id" client_secret = "my_client_secret" client_credentials_manager = SpotifyClientCredentials(client_id,client_secret) sp = spotipy.Spotify(client_credentials_manager = client_credentials_manager) ``` And I get this response ``` --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-4-85ea47b59519> in <module> 3 4 client_credentials_manager = SpotifyClientCredentials(client_id,client_secret) ----> 5 sp = spotipy.Spotify(client_credentials_manager = client_credentials_manager) ~\AppData\Roaming\Python\Python38\site-packages\spotipy\client.py in __init__(self, auth, requests_session, client_credentials_manager, oauth_manager, auth_manager, proxies, requests_timeout, status_forcelist, retries, status_retries, backoff_factor, language) 164 else: 165 if requests_session: # Build a new session. --> 166 self._build_session() 167 else: # Use the Requests API module as a "session". 168 self._session = requests.api ~\AppData\Roaming\Python\Python38\site-packages\spotipy\client.py in _build_session(self) 191 def _build_session(self): 192 self._session = requests.Session() --> 193 retry = urllib3.Retry( 194 total=self.retries, 195 connect=None, TypeError: __init__() got an unexpected keyword argument 'allowed_methods' ``` When I changed it to this as in docs `sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials(client_id = 'my_client_id', client_secret = 'my_client_secret'))` i still have the same error.
Author
Owner

@stephanebruckert commented on GitHub (Feb 28, 2021):

Hello. If you do pip list or pip3 list, what version do you have for requests and urllib3? You should have urllib3>=1.26 and requests>=2.25

<!-- gh-comment-id:787442585 --> @stephanebruckert commented on GitHub (Feb 28, 2021): Hello. If you do `pip list` or `pip3 list`, what version do you have for `requests` and `urllib3`? You should have `urllib3>=1.26` and `requests>=2.25`
Author
Owner

@marcswan commented on GitHub (Feb 28, 2021):

Hello. If you do pip list or pip3 list, what version do you have for requests and urllib3? You should have urllib3>=1.26 and requests>=2.25

Oh, thank you. I've upgraded urllib3 and now it's working!

<!-- gh-comment-id:787445640 --> @marcswan commented on GitHub (Feb 28, 2021): > Hello. If you do `pip list` or `pip3 list`, what version do you have for `requests` and `urllib3`? You should have `urllib3>=1.26` and `requests>=2.25` Oh, thank you. I've upgraded urllib3 and now it's working!
Author
Owner

@stephanebruckert commented on GitHub (Feb 28, 2021):

It's strange though, it should have updated automatically when doing pip3 install spotipy --upgrade

Let's see if someone else complains about it

<!-- gh-comment-id:787446801 --> @stephanebruckert commented on GitHub (Feb 28, 2021): It's strange though, it should have updated automatically when doing `pip3 install spotipy --upgrade` Let's see if someone else complains about it
Author
Owner

@PutuAgastya commented on GitHub (Feb 28, 2021):

Hello, I also encounter the same error message as mentioned above. Upgrading urllib3 fix the error.

Urllib3 was not updated automatically when I update this package. Here's the output when I updated Spotipy package.

pip install --upgrade spotipy --user
Collecting spotipy
Downloading spotipy-2.17.0-py3-none-any.whl (26 kB)
Collecting six>=1.15.0
Using cached six-1.15.0-py2.py3-none-any.whl (10 kB)
Collecting requests>=2.25.0
Using cached requests-2.25.1-py2.py3-none-any.whl (61 kB)
Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in c:\users\agast\appdata\roaming\python\python36\site-packages (from requests>=2.25.0->spotipy) (2019.6.16)
Requirement already satisfied, skipping upgrade: idna<3,>=2.5 in c:\users\agast\appdata\roaming\python\python36\site-packages (from requests>=2.25.0->spotipy) (2.8)
Requirement already satisfied, skipping upgrade: chardet<5,>=3.0.2 in c:\users\agast\appdata\roaming\python\python36\site-packages (from requests>=2.25.0->spotipy) (3.0.4)
Requirement already satisfied, skipping upgrade: urllib3<1.27,>=1.21.1 in c:\users\agast\appdata\roaming\python\python36\site-packages (from requests>=2.25.0->spotipy) (1.25.3)
Installing collected packages: six, requests, spotipy
Attempting uninstall: six
Found existing installation: six 1.12.0
Uninstalling six-1.12.0:
Successfully uninstalled six-1.12.0
Attempting uninstall: requests
Found existing installation: requests 2.22.0
Uninstalling requests-2.22.0:
Successfully uninstalled requests-2.22.0
Attempting uninstall: spotipy
Found existing installation: spotipy 2.16.1
Uninstalling spotipy-2.16.1:
Successfully uninstalled spotipy-2.16.1
Successfully installed requests-2.25.1 six-1.15.0 spotipy-2.17.0

<!-- gh-comment-id:787448242 --> @PutuAgastya commented on GitHub (Feb 28, 2021): Hello, I also encounter the same error message as mentioned above. Upgrading urllib3 fix the error. Urllib3 was not updated automatically when I update this package. Here's the output when I updated Spotipy package. > pip install --upgrade spotipy --user Collecting spotipy Downloading spotipy-2.17.0-py3-none-any.whl (26 kB) Collecting six>=1.15.0 Using cached six-1.15.0-py2.py3-none-any.whl (10 kB) Collecting requests>=2.25.0 Using cached requests-2.25.1-py2.py3-none-any.whl (61 kB) Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in c:\users\agast\appdata\roaming\python\python36\site-packages (from requests>=2.25.0->spotipy) (2019.6.16) Requirement already satisfied, skipping upgrade: idna<3,>=2.5 in c:\users\agast\appdata\roaming\python\python36\site-packages (from requests>=2.25.0->spotipy) (2.8) Requirement already satisfied, skipping upgrade: chardet<5,>=3.0.2 in c:\users\agast\appdata\roaming\python\python36\site-packages (from requests>=2.25.0->spotipy) (3.0.4) Requirement already satisfied, skipping upgrade: urllib3<1.27,>=1.21.1 in c:\users\agast\appdata\roaming\python\python36\site-packages (from requests>=2.25.0->spotipy) (1.25.3) Installing collected packages: six, requests, spotipy Attempting uninstall: six Found existing installation: six 1.12.0 Uninstalling six-1.12.0: Successfully uninstalled six-1.12.0 Attempting uninstall: requests Found existing installation: requests 2.22.0 Uninstalling requests-2.22.0: Successfully uninstalled requests-2.22.0 Attempting uninstall: spotipy Found existing installation: spotipy 2.16.1 Uninstalling spotipy-2.16.1: Successfully uninstalled spotipy-2.16.1 Successfully installed requests-2.25.1 six-1.15.0 spotipy-2.17.0
Author
Owner

@stephanebruckert commented on GitHub (Feb 28, 2021):

requests 2.25.0 wasn't forcing update of urllib3 to 1.26.0.

Should be fine now on spotipy 2.17.1

pip3 install spotipy --upgrade

Thanks for reporting!

<!-- gh-comment-id:787456242 --> @stephanebruckert commented on GitHub (Feb 28, 2021): requests 2.25.0 wasn't forcing update of urllib3 to 1.26.0. Should be fine now on spotipy 2.17.1 pip3 install spotipy --upgrade Thanks for reporting!
Author
Owner

@surenjanath commented on GitHub (May 21, 2021):

oh i got a little tip on this error, if you're outside of the countries that spotify works eg [ US, France etc ], you'd get this error without a vpn, just use vpn and it'll work :)

<!-- gh-comment-id:846096451 --> @surenjanath commented on GitHub (May 21, 2021): oh i got a little tip on this error, if you're outside of the countries that spotify works eg [ US, France etc ], you'd get this error without a vpn, just use vpn and it'll work :)
Author
Owner

@Peter-Schorn commented on GitHub (May 21, 2021):

This error was caused by using the wrong version of urllib3. How could it have anything to do with the country that you are in? The error occurs before any web API requests are even made.

<!-- gh-comment-id:846155832 --> @Peter-Schorn commented on GitHub (May 21, 2021): This error was caused by using the wrong version of urllib3. How could it have anything to do with the country that you are in? The error occurs before any web API requests are even made.
Author
Owner

@jenniferstefaniks commented on GitHub (Aug 22, 2021):

Good night people,
I have the same problem as @marcswan and even upgrading the pip and updating urllib3 and requests, it still gives me the same problem
'init() got an unexpected keyword argument 'allowed_methods'

Would there be another way to resolve this error?

<!-- gh-comment-id:903195245 --> @jenniferstefaniks commented on GitHub (Aug 22, 2021): Good night people, I have the same problem as @marcswan and even upgrading the pip and updating urllib3 and requests, it still gives me the same problem '__init__() got an unexpected keyword argument 'allowed_methods' Would there be another way to resolve this error?
Author
Owner

@stephanebruckert commented on GitHub (Aug 22, 2021):

Hello. If you do pip list or pip3 list, what version do you have for requests and urllib3? You should have urllib3>=1.26 and requests>=2.25

@jenniferstefaniks can you please answer the question above and we'll try to help

<!-- gh-comment-id:903195513 --> @stephanebruckert commented on GitHub (Aug 22, 2021): > Hello. If you do `pip list` or `pip3 list`, what version do you have for `requests` and `urllib3`? You should have `urllib3>=1.26` and `requests>=2.25` @jenniferstefaniks can you please answer the question above and we'll try to help
Author
Owner

@jenniferstefaniks commented on GitHub (Aug 22, 2021):

Good night, they are in the current version. urllib3>=1.26.0
requests>=2.25.0 I'm using collab notebook

Em sáb., 21 de ago. de 2021 às 21:56, Stéphane Bruckert <
@.***> escreveu:

Hello. If you do pip list or pip3 list, what version do you have for
requests and urllib3? You should have urllib3>=1.26 and requests>=2.25

@jenniferstefaniks https://github.com/jenniferstefaniks can you please
answer the question above and we'll try to help


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/plamere/spotipy/issues/647#issuecomment-903195513,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AMDU5BSMUC77VZ2LZ2DTAE3T6BDM3ANCNFSM4YK7V6GA
.
Triage notifications on the go with GitHub Mobile for iOS
https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675
or Android
https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email
.

<!-- gh-comment-id:903196607 --> @jenniferstefaniks commented on GitHub (Aug 22, 2021): Good night, they are in the current version. urllib3>=1.26.0 requests>=2.25.0 I'm using collab notebook Em sáb., 21 de ago. de 2021 às 21:56, Stéphane Bruckert < ***@***.***> escreveu: > Hello. If you do pip list or pip3 list, what version do you have for > requests and urllib3? You should have urllib3>=1.26 and requests>=2.25 > > @jenniferstefaniks <https://github.com/jenniferstefaniks> can you please > answer the question above and we'll try to help > > — > You are receiving this because you were mentioned. > Reply to this email directly, view it on GitHub > <https://github.com/plamere/spotipy/issues/647#issuecomment-903195513>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/AMDU5BSMUC77VZ2LZ2DTAE3T6BDM3ANCNFSM4YK7V6GA> > . > Triage notifications on the go with GitHub Mobile for iOS > <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> > or Android > <https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email> > . >
Author
Owner

@OllySalanson commented on GitHub (Sep 3, 2021):

Hi,

I am receiving the same error message.

spotipy, requests and urllib3 are up to date:
spotipy 2.19.0
urllib3 1.26.6
requests 2.26.0

I'm using ubuntu EC2 AWS with Python 3.8.10.

Traceback (most recent call last): File "main.py", line 197, in <module> trackIds = populateTrackIds() File "main.py", line 57, in populateTrackIds sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id="b95eb7c97a4f4bd5a13ab9da3aad447d", File "/usr/local/lib/python3.8/dist-packages/spotipy/client.py", line 166, in __init__ self._build_session() File "/usr/local/lib/python3.8/dist-packages/spotipy/client.py", line 193, in _build_session retry = urllib3.Retry( TypeError: __init__() got an unexpected keyword argument 'allowed_methods'

<!-- gh-comment-id:912613119 --> @OllySalanson commented on GitHub (Sep 3, 2021): Hi, I am receiving the same error message. spotipy, requests and urllib3 are up to date: spotipy 2.19.0 urllib3 1.26.6 requests 2.26.0 I'm using ubuntu EC2 AWS with Python 3.8.10. `Traceback (most recent call last): File "main.py", line 197, in <module> trackIds = populateTrackIds() File "main.py", line 57, in populateTrackIds sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id="b95eb7c97a4f4bd5a13ab9da3aad447d", File "/usr/local/lib/python3.8/dist-packages/spotipy/client.py", line 166, in __init__ self._build_session() File "/usr/local/lib/python3.8/dist-packages/spotipy/client.py", line 193, in _build_session retry = urllib3.Retry( TypeError: __init__() got an unexpected keyword argument 'allowed_methods' `
Author
Owner

@s2t2 commented on GitHub (Nov 24, 2021):

On colab:

!pip install urllib3 --upgrade 
!pip install requests --upgrade 
!pip install spotipy --upgrade

Then restart the runtime for it to work.

<!-- gh-comment-id:977323718 --> @s2t2 commented on GitHub (Nov 24, 2021): On colab: ``` !pip install urllib3 --upgrade !pip install requests --upgrade !pip install spotipy --upgrade ``` Then restart the runtime for it to work.
Author
Owner

@sebastienmaurette commented on GitHub (Dec 28, 2021):

hello !
Same thing for me.
All my versions have been upgraded

<!-- gh-comment-id:1002009648 --> @sebastienmaurette commented on GitHub (Dec 28, 2021): hello ! Same thing for me. All my versions have been upgraded
Author
Owner

@stephanebruckert commented on GitHub (Dec 28, 2021):

@sebastienmaurette please share your versions of requests and urllib3

Hello. If you do pip list or pip3 list, what version do you have for requests and urllib3? You should have urllib3>=1.26 and requests>=2.25

<!-- gh-comment-id:1002018554 --> @stephanebruckert commented on GitHub (Dec 28, 2021): @sebastienmaurette please share your versions of requests and urllib3 > Hello. If you do `pip list` or `pip3 list`, what version do you have for `requests` and `urllib3`? You should have `urllib3>=1.26` and `requests>=2.25`
Author
Owner

@hikariatama commented on GitHub (Mar 10, 2022):

requests==2.27.1
urllib3==1.26.8
spotipy==2.19.0

pip3 install -U requests urllib3 spotipy have not solved the issue, sadly

line 193, in _build_session
    retry = urllib3.Retry(

TypeError: __init__() got an unexpected keyword argument 'allowed_methods'
<!-- gh-comment-id:1064218250 --> @hikariatama commented on GitHub (Mar 10, 2022): `requests==2.27.1` `urllib3==1.26.8` `spotipy==2.19.0` `pip3 install -U requests urllib3 spotipy` have not solved the issue, sadly ``` line 193, in _build_session retry = urllib3.Retry( TypeError: __init__() got an unexpected keyword argument 'allowed_methods' ```
Author
Owner

@Selfie-bd commented on GitHub (Jun 13, 2022):

TypeError: Client.__init__() got an unexpected keyword argument 'session_name'

When this code

QueueDB = {} ReplyDB = {} FormtDB = {} NubBot = Client( session_name=Config.SESSION_NAME, api_id=int(Config.API_ID), api_hash=Config.API_HASH, bot_token=Config.BOT_TOKEN )

<!-- gh-comment-id:1153359204 --> @Selfie-bd commented on GitHub (Jun 13, 2022): `TypeError: Client.__init__() got an unexpected keyword argument 'session_name' ` When this code `QueueDB = {} ReplyDB = {} FormtDB = {} NubBot = Client( session_name=Config.SESSION_NAME, api_id=int(Config.API_ID), api_hash=Config.API_HASH, bot_token=Config.BOT_TOKEN )`
Author
Owner

@Eeman1113 commented on GitHub (Jul 10, 2022):

Screenshot 2022-07-10 at 4 23 37 PM Having this error in google colab
<!-- gh-comment-id:1179704456 --> @Eeman1113 commented on GitHub (Jul 10, 2022): <img width="1215" alt="Screenshot 2022-07-10 at 4 23 37 PM" src="https://user-images.githubusercontent.com/54275491/178141859-a9e5e6b1-77f2-4a9c-adde-2acc02b32c39.png"> Having this error in google colab
Author
Owner

@samerkhateeb commented on GitHub (Jan 24, 2025):

i removed the line of code "allowed_methods" attribute from the method,
and it worked like charm !!

/usr/local/lib/python3.9/site-packages/apimatic_requests_client_adapter/requests_client.py

retry_strategy = Retry(total=max_retries, backoff_factor=backoff_factor,
#allowed_methods=retry_methods,
status_forcelist=retry_statuses,raise_on_status=False, raise_on_redirect=False)

<!-- gh-comment-id:2613280985 --> @samerkhateeb commented on GitHub (Jan 24, 2025): i removed the line of code "allowed_methods" attribute from the method, and it worked like charm !! /usr/local/lib/python3.9/site-packages/apimatic_requests_client_adapter/requests_client.py retry_strategy = Retry(total=max_retries, backoff_factor=backoff_factor, #allowed_methods=retry_methods, status_forcelist=retry_statuses,raise_on_status=False, raise_on_redirect=False)
Author
Owner

@dieser-niko commented on GitHub (Jan 24, 2025):

@samerkhateeb could you share the result of using pip freeze?

<!-- gh-comment-id:2613348736 --> @dieser-niko commented on GitHub (Jan 24, 2025): @samerkhateeb could you share the result of using `pip freeze`?
Author
Owner

@samerkhateeb commented on GitHub (Jan 24, 2025):

@dieser-niko which packages you are looking for ? i'll give you the pip freeze of it.

<!-- gh-comment-id:2613461861 --> @samerkhateeb commented on GitHub (Jan 24, 2025): @dieser-niko which packages you are looking for ? i'll give you the pip freeze of it.
Author
Owner

@dieser-niko commented on GitHub (Jan 24, 2025):

I'm mostly interested in spotipy, requests and especially urllib3.

<!-- gh-comment-id:2613524454 --> @dieser-niko commented on GitHub (Jan 24, 2025): I'm mostly interested in spotipy, requests and especially urllib3.
Author
Owner

@samerkhateeb commented on GitHub (Jan 24, 2025):

@dieser-niko find the following:

requests==2.25.0
requests-file==1.5.1
requests-oauthlib==1.3.0
requests-toolbelt==0.9.1
rfc3986==1.5.0
rjsmin==1.1.0
rsa==4.7.2
selenium==3.141.0
service-identity==18.1.0
simplejson==3.17.2
six==1.15.0
sniffio==1.2.0
soupsieve==2.0.1
spotipy==2.25.0
sqlparse==0.3.1
starlette==0.13.6
streamlink==1.4.1
textblob==0.15.3
threadpoolctl==2.1.0
tomli==2.2.1
tqdm==4.61.0
twilio==6.51.0
Twisted==21.2.0
txaio==21.2.1
typing-extensions==3.7.4.3
typish==1.7.0
tzlocal==2.1
Unidecode==1.1.1
urllib3==1.26.1
uvicorn==0.13.4
virtualenv==20.28.0
vote==1.0.2
webencodings==0.5.1
websocket-client==0.57.0
wells==1.4.1
youtube-dl==2020.6.16.1
zeep==3.4.0
zope.interface==5.1.0

<!-- gh-comment-id:2613547193 --> @samerkhateeb commented on GitHub (Jan 24, 2025): @dieser-niko find the following: requests==2.25.0 requests-file==1.5.1 requests-oauthlib==1.3.0 requests-toolbelt==0.9.1 rfc3986==1.5.0 rjsmin==1.1.0 rsa==4.7.2 selenium==3.141.0 service-identity==18.1.0 simplejson==3.17.2 six==1.15.0 sniffio==1.2.0 soupsieve==2.0.1 spotipy==2.25.0 sqlparse==0.3.1 starlette==0.13.6 streamlink==1.4.1 textblob==0.15.3 threadpoolctl==2.1.0 tomli==2.2.1 tqdm==4.61.0 twilio==6.51.0 Twisted==21.2.0 txaio==21.2.1 typing-extensions==3.7.4.3 typish==1.7.0 tzlocal==2.1 Unidecode==1.1.1 urllib3==1.26.1 uvicorn==0.13.4 virtualenv==20.28.0 vote==1.0.2 webencodings==0.5.1 websocket-client==0.57.0 wells==1.4.1 youtube-dl==2020.6.16.1 zeep==3.4.0 zope.interface==5.1.0
Author
Owner

@dieser-niko commented on GitHub (Feb 7, 2025):

@samerkhateeb sorry, but I wasn't able to replicate your error, just too much going on there.
Just a quick question, do you need all these libraries for your project? If not, then please consider using virtual environments instead. Might fix the issue.

<!-- gh-comment-id:2643338541 --> @dieser-niko commented on GitHub (Feb 7, 2025): @samerkhateeb sorry, but I wasn't able to replicate your error, just too much going on there. Just a quick question, do you need all these libraries for your project? If not, then please consider using virtual environments instead. Might fix the issue.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#386
No description provided.