错误:post() 得到了意外的关键字参数“代理”

问题描述 投票:0回答:1

我正在使用 youtube-search-python 获取包含歌曲名称的数组的 URL,但不断弹出此错误:

post() got an unexpected keyword argument 'proxies'

我是Python新手,我一直在四处寻找,但找不到任何可以修复此错误的有用信息(至少我明白)。

这是引发错误的代码:

 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)

这是错误堆栈跟踪:

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'

错误必须在

playlist.search_for_songs
中,因为它没有打印任何内容。这是所有的代码:

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)
python youtube
1个回答
0
投票

我相信您正在使用

httpx
版本0.28.0(我猜不是连续的,而是作为另一个包的一部分)。在此版本中,
post
方法确实没有声明
proxies
参数。比较一下:

>>> httpx.__version__
'0.27.2'
>>> 'proxies' in inspect.getargs(httpx.post.__code__).args
True

>>> httpx.__version__
'0.28.1'
>>> 'proxies' in inspect.getargs(httpx.post.__code__).args
False

如果可能的话,您应该将

httpx
降级到版本 0.27,如下所示:

pip install --force-reinstall 'httpx<0.28'

我认为合理的方法是首先在一个新鲜的、独立的环境中尝试。

© www.soinside.com 2019 - 2024. All rights reserved.