我正在尝试使用Spotipy Python库调用Spotify API。我收到一个'PermissionError: [Errno 13] Permission denied'错误。
我使用的是以Debian为操作系统的GCP计算引擎。
错误在下面
Traceback (most recent call last):<br>
File "<stdin>", line 1, in <module><br>
File "/home/#####/.local/lib/python3.7/site-packages/spotipy/client.py", line 1307, in current_use
r_recently_played<br>
before=before,<br>
File "/home/#####/.local/lib/python3.7/site-packages/spotipy/client.py", line 291, in _get<br>
return self._internal_call("GET", url, payload, kwargs)<br>
File "/home/#####/.local/lib/python3.7/site-packages/spotipy/client.py", line 221, in _internal_ca
ll<br>
headers = self._auth_headers()<br>
File "/home/#####/.local/lib/python3.7/site-packages/spotipy/client.py", line 212, in _auth_header
s<br>
token = self.auth_manager.get_access_token(as_dict=False)<br>
File "/home/#####/.local/lib/python3.7/site-packages/spotipy/oauth2.py", line 484, in get_access_t
oken<br>
"code": code or self.get_auth_response(),<br>
File "/home/#####/.local/lib/python3.7/site-packages/spotipy/oauth2.py", line 439, in get_auth_res
ponse<br>
return self._get_auth_response_local_server(redirect_port)<br>
File "/home/#####/.local/lib/python3.7/site-packages/spotipy/oauth2.py", line 405, in _get_auth_re
sponse_local_server<br>
server = start_local_http_server(redirect_port)<br>
File "/home/#####/.local/lib/python3.7/site-packages/spotipy/oauth2.py", line 1227, in start_local
_http_server<br>
server = HTTPServer(("127.0.0.1", port), handler)<br>
File "/usr/lib/python3.7/socketserver.py", line 452, in __init__<br>
self.server_bind()<br>
File "/usr/lib/python3.7/http/server.py", line 137, in server_bind<br>
socketserver.TCPServer.server_bind(self)<br>
File "/usr/lib/python3.7/socketserver.py", line 466, in server_bind<br>
self.socket.bind(self.server_address)<br>
PermissionError: [Errno 13] Permission denied<br>代码示例如下
import spotipy
from spotipy.oauth2 import SpotifyOAuth
scope = 'user-read-recently-played'
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(scope=scope))
played = sp.current_user_recently_played()我已经在我认为是相关目录的地方做了chmod 0775 -R,但仍然卡住了。
发布于 2021-02-09 03:24:27
我建议尝试使用不同的方法。下面是我在Spotify管道中使用的内容:
import spotipy
import spotipy.util as util
import os
un = os.environ['un']
scope = 'user-read-recently-played'
cid = os.environ['cid']
csid = os.environ['csid']
redr = r'http://localhost:8888/callback/'
token = util.prompt_for_user_token(un,scope,cid,csid,redr)
sp = spotipy.Spotify(auth=token)
results = sp.current_user_recently_played()其中un是我的用户名,cid和csid是我的开发者账户的密钥/秘密密钥,redr只是重定向的本地网页。
https://stackoverflow.com/questions/66107769
复制相似问题