Google.auth.exceptions.refresherror: ('kein Zugriffs -Token als Antwort.', {'id_token':Python

Python-Programme
Anonymous
 Google.auth.exceptions.refresherror: ('kein Zugriffs -Token als Antwort.', {'id_token':

Post by Anonymous »

Ich versuche eine Verbindung zum Google Drive herzustellen, um einige Vorgänge im Laufwerksordner auszuführen. Ich habe eine Funktion gebaut und es hat funktioniert. Aber als ich versuchte, OOP und definierte Klassen implementieren zu können, erhalte ich diesen Fehler. Ich habe alle Env- und Konfigurationsvariablen überprüft und sie sind korrekt.

Code: Select all

from google.oauth2 import service_account
from googleapiclient.discovery import build

SCOPES = ['https://www.googleapis.com/auth/drive']
SERVICE_ACCOUNT_FILE = 'c4s-drive-secretkey.json'

credentials = service_account.Credentials.from_service_account_file(
SERVICE_ACCOUNT_FILE,
scopes=SCOPES
)

service = build('drive', 'v3', credentials=credentials)

query = f"'1Qe***************MzGVwQ-' in parents and trashed = false"
results = service.files().list(q=query,

fields="files(id, name)",
supportsAllDrives=True,
includeItemsFromAllDrives=True).execute()
files = results.get('files', [])
if files:
for file in files:
print(f"Deleting {file['name']} ({file['id']})")
service.files().delete(fileId=file['id'],supportsAllDrives=True).execute()
< /code>
oop: nicht funktioniertclass DriveLoader:
def __init__(self, PARENT_FOLDER_ID,download_path,SCOPES,SERVICE_ACC_FILE):
self.SCOPES = SCOPES
self.SERVICE_ACC_FILE = SERVICE_ACC_FILE
self.PARENT_FOLDER_ID = PARENT_FOLDER_ID
self.download_path = download_path
creds = service_account.Credentials.from_service_account_file(self.SERVICE_ACC_FILE, scopes = self.SCOPES)
self.service = build('drive', 'v3', credentials=creds)

def clear_folder(self):
query = f"'{self.PARENT_FOLDER_ID}' in parents and trashed = false"
results = self.service.files().list(q=query,
fields="files(id, name)",
supportsAllDrives=True,
includeItemsFromAllDrives=True).execute()

files = results.get('files', [])

if files:
for file in files:
print(f"Deleting {file['name']} ({file['id']})")
self.service.files().delete(fileId=file['id'],supportsAllDrives=True).execute()

< /code>
Script.py:
class ExtractLoad:

def __init__(self, url, web_username, web_pass, form_lst, download_path, suffix,PARENT_FOLDER_ID,SCOPE,SERVICE_ACC_FILE):
self.web_username = web_username
self.web_pass = web_pass
self.download_path = download_path
self.form_lst = form_lst
self.suffix = suffix
self.url = url
self.PARENT_FOLDER_ID = PARENT_FOLDER_ID
self.SCOPE = SCOPE
self.SERVICE_ACC_FILE = SERVICE_ACC_FILE
def drive_loader(self):

loader = DriveLoader(self.PARENT_FOLDER_ID,self.download_path,self.SCOPE,self.SERVICE_ACC_FILE)
loader.clear_folder()

< /code>
Script.py:
class C4SExecutor:
def __init__(self):
load_dotenv()
self.ENV = dotenv_values(".env")
with open("config.toml", "r") as file:
self.config = toml.load(file)

def run_pipeline(self):
for form in self.config["FORMS"]:
pipeline = ExtractLoad(form["url"], self.ENV["web_username"], self.ENV["web_pass"], form["forms"], form["download_path"], form["suffix"],form["PARENT_FOLDER_ID"], self.ENV["SCOPE"], self.ENV["SERVICE_ACC_FILE"])

pipeline.drive_loader()
logger.info("screening files uploaded to drive")
< /code>
Main.py:
from script import C4SExecutor

executor = C4SExecutor()
executor.run_pipeline()

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post