spotipy-dev / spotipy

A light weight Python library for the Spotify Web API
http://spotipy.readthedocs.org
MIT License
4.97k stars 956 forks source link

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

Open marcswan opened 3 years ago

marcswan commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 .

OllySalanson commented 3 years ago

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 commented 2 years ago

On colab:

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

Then restart the runtime for it to work.

sebastienmaurette commented 2 years ago

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

stephanebruckert commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago
Screenshot 2022-07-10 at 4 23 37 PM

Having this error in google colab