F
F
FaustGette2020-06-01 18:11:43
Python
FaustGette, 2020-06-01 18:11:43

No errors synchronously, asynchronously - WRONG SSL VERSION NUMBER. How to fix it?

Problem with calling Google Drive API

Synchronous call does not throw any errors:

def backup_everything(*bases):
    tasks = [
        i.backup()
        for i in bases
    ]

Result:
5ed5116bc86b6028833079.png

Async gives an SSL certificate error (as well as multithreading via unsync, by the way):
async def backup_coro(*bases):
    loop = asyncio.get_event_loop()
    tasks = [
        loop.run_in_executor(None, i.backup)
        for i in bases
    ]
    return await asyncio.gather(*tasks)

asyncio.run(backup_coro(*bases))

Result:
5ed51722ad6e5770595904.png

The backup() methods of different classes refer to the function of the same name:
def backup(f_name: str,  f_path: str) -> None:
    # удалить старые версии файлов
    last_backup = drive.search({'name': f_name})
    if last_backup:
        del_item(last_backup[0]['id'], "Previous base deleted")
    try:
        # ID папки, куда заливать файл
        fold_id = folder(BACKUP_FOLDER_NAME)
        f_mime_type = mimeTypes[file_ext(f_name)]
        drive.upload_file(f_name, f_path, f_mime_type, fold_id)
    except Exception as trouble:
        print(trouble, f_path, 'Terminating...', sep='\n')
    else:
        print(f"File: '{f_name}' uploaded")

Which, in turn, refers to the class methods for working with the Google Drive API.

The method where the error occurs:
def del_item(self, _id: str) -> None:
        self.drive_service.files().delete(fileId=_id).execute()

Where drive_service is googleapiclient.discovery.build('drive', 'v3', credentials). Nothing out of the ordinary, in other words.

Question(s): Why is this happening? How to fix it? Do Google libraries have more elegant ways to work asynchronously?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question