首页 > 解决方案 > PermissionError:[Errno 13] 权限被拒绝-Spotipy

问题描述

我正在尝试使用 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了我认为相关的目录,但仍然卡住了。

标签: pythongoogle-compute-enginespotifyspotipy

解决方案


我建议尝试使用不同的方法。这是我用于 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()

我的用户名在哪里uncid并且csid是我的开发者帐户的密钥/秘密密钥,而 redr 只是用于重定向的本地网页。


推荐阅读