From 2ab14d9cd30df7058b6f6863bbb47d00b3890f4c Mon Sep 17 00:00:00 2001 From: Diego Pereyra Date: Mon, 8 Aug 2022 21:59:27 -0300 Subject: [PATCH] Fix save token (using pickle) --- bumblebee_status/modules/contrib/gcalendar.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bumblebee_status/modules/contrib/gcalendar.py b/bumblebee_status/modules/contrib/gcalendar.py index e438bdd..c88cfad 100644 --- a/bumblebee_status/modules/contrib/gcalendar.py +++ b/bumblebee_status/modules/contrib/gcalendar.py @@ -29,6 +29,7 @@ import core.decorators import datetime import os.path +import pickle from google.auth.transport.requests import Request from google.oauth2.credentials import Credentials @@ -60,7 +61,8 @@ class Module(core.module.Module): # created automatically when the authorization flow completes for the first # time. if os.path.exists(self.__token): - creds = Credentials.from_authorized_user_file(self.__token, SCOPES) + with open(self.__token, 'rb') as token: + creds = pickle.load(token) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: @@ -71,8 +73,8 @@ class Module(core.module.Module): ) creds = flow.run_local_server(port=0) # Save the credentials for the next run - with open(self.__token, "w") as token: - token.write(creds.to_json()) + with open(self.__token, 'wb') as token: + pickle.dump(creds, token) try: service = build("calendar", "v3", credentials=creds)