Ошибка TimeoutError: [WinError 10060] python pydrive

У меня есть код:

import asyncio import os import time

from pydrive.auth import GoogleAuth from pydrive.drive import GoogleDrive from threading import Thread

gauth = GoogleAuth()
# Try to load saved client credentials gauth.LoadCredentialsFile("mycreds.txt") if gauth.credentials is None:
    # Authenticate if they're not there
    gauth.LocalWebserverAuth() elif gauth.access_token_expired:
    # Refresh them if expired
    gauth.Refresh() else:
    # Initialize the saved creds
    gauth.Authorize()
# Save the current credentials to a file gauth.SaveCredentialsFile("mycreds.txt") clear = lambda: os.system('cls') update = False


def addContentToTheFile(file_content):
    file_name = 'chat.txt'
    drive = GoogleDrive(gauth)
    file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList()
    for file1 in file_list:
        if file1['title'] == file_name:
            oldContent = readFile('chat.txt')
            newContent = oldContent + '\n' + file_content
            file1.SetContentString(newContent)
            file1.Upload()
    return f'File {file_name} was uploaded'


def readFile(file_name):
    drive = GoogleDrive(gauth)
    file_list = drive.ListFile({'q': "'root' in parents and trashed=false"}).GetList()
    for file1 in file_list:
        if file1['title'] == file_name:
            file1.GetContentFile(filename=file_name)
            content_bytes = file1.content
            string_data = content_bytes.read().decode('utf-8')
            return string_data


def updateChat():
    global oldChat, update
    _tmp = readFile(file_name='chat.txt')
    print(_tmp)
    with open('chat.txt', 'r', encoding='UTF-8') as Reader:
        oldChat = Reader.read()
    while True:
        with open('chat.txt', 'r', encoding='UTF-8') as Reader:
            newChat = Reader.read()
        if oldChat != newChat or update:
            update = False
            _tmp = readFile(file_name='chat.txt')
            clear()
            print(_tmp)
            oldChat = newChat
        time.sleep(1)


def getUserMessages():
    global name, update
    while True:
        a = input()
        if a != '':
            a = name + ': ' + a
            addContentToTheFile(file_content=a)
            update = True
        time.sleep(5)


def processingNewMessages():
    while True:
        readFile('chat.txt')
        time.sleep(5)


async def main():
    global oldChat, name
    print('Введите ваше имя:')
    name = input()
    clear()
    Thread(target=updateChat).start()
    Thread(target=getUserMessages).start()
    Thread(target=processingNewMessages).start()


asyncio.run(main())

Это что-то вроде чата, реализованного через библиотеку pydrive. Проблема в том, что иногда, на старте, программа выдаёт следующую ошибку:

Exception in thread Thread-3 (processingNewMessehes):
Traceback (most recent call last):
  File "threading.py", line 1009, in _bootstrap_inner
  File "threading.py", line 946, in run
  File "main.py", line 83, in processingNewMessehes
  File "main.py", line 43, in readFile
  File "pydrive\apiattr.py", line 162, in GetList
  File "pydrive\apiattr.py", line 146, in __next__
  File "pydrive\auth.py", line 75, in _decorated
  File "pydrive\files.py", line 63, in _GetList
  File "googleapiclient\_helpers.py", line 131, in positional_wrapper
  File "googleapiclient\http.py", line 922, in execute
  File "googleapiclient\http.py", line 221, in _retry_request
  File "googleapiclient\http.py", line 190, in _retry_request
  File "oauth2client\transport.py", line 173, in new_request
  File "oauth2client\transport.py", line 280, in request
  File "httplib2\__init__.py", line 1701, in request
  File "httplib2\__init__.py", line 1421, in _request
  File "httplib2\__init__.py", line 1343, in _conn_request
  File "httplib2\__init__.py", line 1133, in connect
TimeoutError: [WinError 10060] Попытка установить соединение была безуспешной, т.к. от другого компьютера за требуемое время не получен нужный отклик, или было разорвано уже установленное соединение из-за неверного отклика уже подключенного компьютера

Так же эта ошибка возникает, если долго держать консоль открытой (минут 15-20). Я уже внёс в исключение антивируса (у меня защитник windows) путь проекта и IDE, но pyCharm всё равно ругается на то, что проект не в инклюде у скана антивируса. Подскажите пожалуйста, как это можно исправить. Заранее спасибо!


Ответы (0 шт):