python - 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
了我认为相关的目录,但仍然卡住了。
解决方案
我建议尝试使用不同的方法。这是我用于 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 只是用于重定向的本地网页。
推荐阅读
- r - 在格点图上显示值
- powershell - 简单的 Powershell 7.0 脚本
- angular - Angular 11 在 SSR @nguniversal/express-engine 上运行 ReferenceError: globalThis is not defined
- bash - 如何连接路径(读入文件)和bash中的字符串?
- python - 在python中使用变量字符串作为对象参数
- python - 将网站的响应代码和响应时间放入单个循环中
- python - 应用函数需要很长时间才能运行
- php - php preg_replace 没有放回破折号?
- python - 尝试使用 python ftplib 从 NCBI ftp 下载一系列档案,但 ftplib 在长文件传输结束时冻结
- c++ - 从 git 克隆时 Wxwidgets setup.h 文件更改