如何解决PermissionError: [Errno 13] 权限被拒绝 - Spotipy
我正在尝试使用 Spotipy Python 库调用 Spotify API。我收到了 'PermissionError: [Errno 13] Permission denied'
错误。
我使用 GCP 计算引擎,以 Debian 作为操作系统。
错误如下
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
,但仍然卡住了。
解决方法
我建议尝试使用不同的方法。这是我用于 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 只是用于重定向的本地网页。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。