I'm using youtube-search-python to get the URLs of an array with song names but this error keeps popping up:
post() got an unexpected keyword argument 'proxies'
I'm new to Python and I've been looking around but I couldn't find nothing useful for fixing this error (at least that I understood).
This is the code that is throwing the error:
elif "open.spotify.com" == url_procesed.hostname:
try:
playlist = Playlist(client_id, client_secret)
playlist_tracks = playlist.get_playlist_tracks(url)
link_list = playlist.search_for_songs(playlist_tracks)
print(link_list)
Here's the error stack trace:
Traceback (most recent call last):
File "G:\Bot_v1.1.2\spoty_handler.py", line 69, in <module>
playlist.search_for_songs(song_array)
File "G:\Bot_v1.1.2\spoty_handler.py", line 48, in search_for_songs
search = VideosSearch(song, limit=1)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\TarjetaCiudadana\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\youtubesearchpython\search.py", line 148, in __init__
self.sync_create()
File "C:\Users\TarjetaCiudadana\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\youtubesearchpython\core\search.py", line 29, in sync_create
self._makeRequest()
File "C:\Users\TarjetaCiudadana\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\youtubesearchpython\core\search.py", line 51, in _makeRequest
request = self.syncPostRequest()
^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\TarjetaCiudadana\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\youtubesearchpython\core\requests.py", line 20, in syncPostRequest
return httpx.post(
^^^^^^^^^^^
TypeError: post() got an unexpected keyword argument 'proxies'
The error must be in playlist.search_for_songs
because it doesn't print anything. Here is the code for all of it:
import os
import spotipy
from spotipy.oauth2 import SpotifyClientCredentials
from pytube import YouTube
from youtubesearchpython import VideosSearch
from dotenv import load_dotenv
class Playlist:
def __init__(self, client_id, client_secret):
self.client_id = client_id
self.client_secret = client_secret
load_dotenv()
def get_playlist_tracks(self, playlist_url):
auth_manager = SpotifyClientCredentials(client_id=self.client_id, client_secret=self.client_secret)
sp = spotipy.Spotify(auth_manager=auth_manager)
results = sp.playlist_tracks(playlist_url)
artists_songs_dict = []
for item in results['items']:
track = item['track']
song_name = track['name']
#artist_names = [artist['name'] for artist in track['artists']]
artists_songs_dict.append(song_name)
return artists_songs_dict
def search_for_songs(self, song_dict):
link_list = []
for songs in song_dict:
for song in songs:
search = VideosSearch(song, limit=1)
results = search.result()
link = results['result'][0]['link']
link_list.append(link)
return link_list
TOKEN_1 = os.getenv("MY_TOKEN_1")
TOKEN_2= os.getenv("MY_TOKEN_2")
playlist= Playlist(client_id, client_secret)
song_array= playlist.get_playlist_tracks("https://open.spotify.com/playlist/0drb98YI5Kk0ENtWXIS67y?si=bEHhpXlUThSyKkxNxkMCeg")
playlist.search_for_songs(song_array)
I believe you are using httpx
version 0.28.0 or above. In this version, the post
method really doesn't have the proxies
parameter declared. Compare this:
>>> httpx.__version__
'0.27.2'
>>> 'proxies' in inspect.getargs(httpx.post.__code__).args
True
versus
>>> httpx.__version__
'0.28.1'
>>> 'proxies' in inspect.getargs(httpx.post.__code__).args
False
You might want to consider downgrading httpx
to version 0.27 if possible, like so:
pip install --force-reinstall 'httpx<0.28'
I think a reasonable approach would be to try it in a fresh, separate environment first.