TypeError: __init__() got an unexpected keyword argument 'allowed_methods'
marcswan opened this issue · 17 comments
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.
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
Hello. If you do
pip list
orpip3 list
, what version do you have forrequests
andurllib3
? You should haveurllib3>=1.26
andrequests>=2.25
Oh, thank you. I've upgraded urllib3 and now it's working!
It's strange though, it should have updated automatically when doing pip3 install spotipy --upgrade
Let's see if someone else complains about it
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
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!
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 :)
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.
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?
Hello. If you do
pip list
orpip3 list
, what version do you have forrequests
andurllib3
? You should haveurllib3>=1.26
andrequests>=2.25
@jenniferstefaniks can you please answer the question above and we'll try to help
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'
On colab:
!pip install urllib3 --upgrade
!pip install requests --upgrade
!pip install spotipy --upgrade
Then restart the runtime for it to work.
hello !
Same thing for me.
All my versions have been upgraded
@sebastienmaurette please share your versions of requests and urllib3
Hello. If you do
pip list
orpip3 list
, what version do you have forrequests
andurllib3
? You should haveurllib3>=1.26
andrequests>=2.25
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'
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 )