'I am receiving a [WinError 10053] (established connection aborted by host machine) when requesting thumbnail change with YouTube data API

So I am trying to make a software that swaps thumbnails on youtube videos and records the views that each thumbnail gets over an hour. This will tell me which thumbnail is better. The problem I am running into is in my thumbnail test loop. The first time it runs, the thumbnail and title are changed perfectly fine, but after running sleep() for over what seems like a 30 minute limit, I get a connection abort error (ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine)

I've tried everything I can think of with my very limited coding experience (like this is my first actual project). I've also looked at other people's posts about this issue but none fo them have helped.

Here is the function that the code breaks at, I can provide the entire project if needed, some of my variable names are a bit sus so I hesitate to post it in its entirety lol.

    viewPerHour = []
    viewRaw = []
    initialViews = None
    lastViews = None

    # get starting info-views
    views_response = views_request.execute()
    for item in views_response['items']:
        initialViews = item['statistics']['viewCount']
        initialViews = int(initialViews)
    print("initial views= ", initialViews)

    # Data Aquisition
    count = 0
    while(count <= 4):
        # swap to thumbnailData[1]
        youtubeAuth.thumbnails().set(
            videoId=videoId[0],
            media_body=MediaFileUpload("1.png")
        ).execute()
        SwapTitle(videoTitle1, videoDes, videoId[0])
        print('swapped to thumbnail 1')
        print('current view pre hour: ', viewPerHour)

        # record data
        flag = 1
        currentViews = getViews()
        if flag == 1:
            viewPerHour.append(currentViews - initialViews)
            viewRaw.append(currentViews)
            flag = 0
        else:
            viewPerHour.append(currentViews - lastViews)
            viewRaw.append(currentViews)
        lastViews = currentViews

        count += 1

        # swap to thumbnailData[2]
        youtubeAuth.thumbnails().set( 
            videoId=videoId[0],
            media_body=MediaFileUpload("2.png")
        ).execute()
        SwapTitle(videoTitle2, videoDes, videoId[0])
        print('swapped to thumbnail 2')
        print('current view pre hour: ', viewPerHour)
        i = 0
        if i != 2:
            time.sleep(1200)
            print('Current Views', getViews())
            i += 1

        # record data
        currentViews = getViews()
        viewPerHour.append(currentViews - lastViews)
        viewRaw.append(currentViews)
        lastViews = currentViews
        count += 1

    for items in viewPerHour:
        print('viewPerHour: ', items)
    for items in viewRaw:
        print('viewRaw: ', items)

    # get best Thumbnail
    bestThumbnail = DoTheThing(tnCount, count / tnCount, viewPerHour)

    return bestThumbnail 

Here is the error message I get, It happens when youtubeAuth.thumbnails().set() is called most times for thumbnail 2 in the first iteration of the loop, but today I ran it and it failed at thumbnail 1 on the second iteration fo the loop

Traceback (most recent call last):
  File "C:\Users\Fingle\Desktop\yt_project\tn_swap.py", line 360, in <module>
    bestThumbnail = TestThumbnail(videoId)
  File "C:\Users\Fingle\Desktop\yt_project\tn_swap.py", line 202, in TestThumbnail
    youtubeAuth.thumbnails().set(
  File "C:\Users\Fingle\AppData\Local\Programs\Python\Python38\lib\site-packages\googleapiclient\_helpers.py", line 131, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "C:\Users\Fingle\AppData\Local\Programs\Python\Python38\lib\site-packages\googleapiclient\http.py", line 922, in execute
    resp, content = _retry_request(
  File "C:\Users\Fingle\AppData\Local\Programs\Python\Python38\lib\site-packages\googleapiclient\http.py", line 221, in _retry_request
    raise exception
  File "C:\Users\Fingle\AppData\Local\Programs\Python\Python38\lib\site-packages\googleapiclient\http.py", line 190, in _retry_request
    resp, content = http.request(uri, method, *args, **kwargs)
  File "C:\Users\Fingle\AppData\Local\Programs\Python\Python38\lib\site-packages\google_auth_httplib2.py", line 218, in request
    response, content = self.http.request(
  File "C:\Users\Fingle\AppData\Local\Programs\Python\Python38\lib\site-packages\httplib2\__init__.py", line 1725, in request
    (response, content) = self._request(
  File "C:\Users\Fingle\AppData\Local\Programs\Python\Python38\lib\site-packages\httplib2\__init__.py", line 1441, in _request
    (response, content) = self._conn_request(conn, request_uri, method, body, headers)
  File "C:\Users\Fingle\AppData\Local\Programs\Python\Python38\lib\site-packages\httplib2\__init__.py", line 1364, in _conn_request
    conn.request(method, request_uri, body, headers)
  File "C:\Users\Fingle\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1255, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "C:\Users\Fingle\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1301, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "C:\Users\Fingle\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1250, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "C:\Users\Fingle\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 1049, in _send_output
    self.send(chunk)
  File "C:\Users\Fingle\AppData\Local\Programs\Python\Python38\lib\http\client.py", line 971, in send
    self.sock.sendall(data)
  File "C:\Users\Fingle\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1204, in sendall
    v = self.send(byte_view[count:])
  File "C:\Users\Fingle\AppData\Local\Programs\Python\Python38\lib\ssl.py", line 1173, in send
    return self._sslobj.write(data)
ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

Thanks in advance for any help! I wish I could just figure it out on my own and not bother anyone but I've hit a wall.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source