Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
marcswan opened this issue Feb 28, 2021 · 17 comments
Open

Comments

@marcswan
Copy link

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.

@stephanebruckert
Copy link
Member

stephanebruckert commented 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

@marcswan
Copy link
Author

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!

@stephanebruckert
Copy link
Member

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

Let's see if someone else complains about it

@PutuAgastya
Copy link

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

@stephanebruckert
Copy link
Member

stephanebruckert commented 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!

@surenjanath
Copy link

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 :)

@Peter-Schorn
Copy link
Contributor

Peter-Schorn commented 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.

@jenniferstefaniks
Copy link

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?

@stephanebruckert
Copy link
Member

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

@jenniferstefaniks
Copy link

jenniferstefaniks commented Aug 22, 2021 via email

@OllySalanson
Copy link

OllySalanson commented 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'

@s2t2
Copy link
Contributor

s2t2 commented 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.

@sebastienmaurette
Copy link

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

@stephanebruckert
Copy link
Member

@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

@hikariatama
Copy link

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'

@Selfie-bd
Copy link

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 )

@Eeman1113
Copy link

Screenshot 2022-07-10 at 4 23 37 PM

Having this error in google colab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests