api - 谷歌日历 API 拒绝 Errno 13 权限
问题描述
我正在将我的应用程序与 Google 日历 API 集成,但是在使用 ubuntu 运行脚本时,出现权限错误。
我在开发者的仪表板中启用了 Google Calendar API 并下载了 client_secret.json 文件
为什么我在这里收到权限错误?
这是我正在运行的脚本
# IMPORT STATEMENTS
# Credit: https://learndataanalysis.org/google-py-file-source-code/
CLIENT_SECRET_FILE = 'client_secret_eir.json'
API_NAME = 'calendar'
API_VERSION = 'v3'
SCOPES = ['https://www.googleapis.com/auth/calendar']
service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)
def Create_Service(client_secret_file, api_name, api_version, *scopes):
print(client_secret_file, api_name, api_version, scopes, sep='-')
CLIENT_SECRET_FILE = client_secret_file
API_SERVICE_NAME = api_name
API_VERSION = api_version
SCOPES = [scope for scope in scopes[0]]
print(SCOPES)
cred = None
pickle_file = f'token_{API_SERVICE_NAME}_{API_VERSION}.pickle'
# print(pickle_file)
if os.path.exists(pickle_file):
with open(pickle_file, 'rb') as token:
cred = pickle.load(token)
if not cred or not cred.valid:
if cred and cred.expired and cred.refresh_token:
cred.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRET_FILE, SCOPES)
cred = flow.run_local_server()
with open(pickle_file, 'wb') as token:
pickle.dump(cred, token)
try:
service = build(API_SERVICE_NAME, API_VERSION, credentials=cred)
print(API_SERVICE_NAME, 'service created successfully')
return service
except Exception as e:
print(e)
return None
def convert_to_RFC_datetime(year=1900, month=1, day=1, hour=0, minute=0):
dt = datetime.datetime(year, month, day, hour, minute, 0).isoformat() + 'Z'
return dt
错误信息
client_secret_eir.json-calendar-v3-(['https://www.googleapis.com/auth/calendar'],)
['https://www.googleapis.com/auth/calendar']
Traceback (most recent call last):
File "quickstart.py", line 56, in <module>
service = Create_Service(CLIENT_SECRET_FILE, API_NAME, API_VERSION, SCOPES)
File "quickstart.py", line 33, in Create_Service
cred = flow.run_local_server()
File "/usr/local/lib/python3.8/dist-packages/google_auth_oauthlib/flow.py", line 460, in run_local_server
local_server = wsgiref.simple_server.make_server(
File "/usr/lib/python3.8/wsgiref/simple_server.py", line 154, in make_server
server = server_class((host, port), handler_class)
File "/usr/lib/python3.8/socketserver.py", line 452, in __init__
self.server_bind()
File "/usr/lib/python3.8/wsgiref/simple_server.py", line 50, in server_bind
HTTPServer.server_bind(self)
File "/usr/lib/python3.8/http/server.py", line 138, in server_bind
socketserver.TCPServer.server_bind(self)
File "/usr/lib/python3.8/socketserver.py", line 466, in server_bind
self.socket.bind(self.server_address)
PermissionError: [Errno 13] Permission denied
解决方案
推荐阅读
- reactjs - 如何根据状态数组变量的更改在 React 中重新渲染
- regex - 什么是 regex::Regex::replace 的 hyperscan::Regex 等价物?
- flutter - 在颤振上使用 getx 传递参数
- c - 在 C 中使用函数的 Pangram
- python - Python如何根据多个变量创建排名?
- visual-studio-code - 为什么 vscode-eslint 使用与 ESLint 不同的“根”?
- reactjs - 如何将这些数据从子组件传递给父组件?
- python - TypeError:“dict”和“dict”排行榜命令错误的实例之间不支持“<”
- swiftui - 在初始化期间确定 NavigationLink 目标
- java - 二叉树搜索非键值