0

I currently have the following method implemented that is meant to make a GET request (indefinitely until the call is successful in the event that the call is not successful):

    def request_with_error_handling(self, url, filename):
        current_datetime = str(datetime.now()).replace(" ", "_").replace(":",
                                                                         ".")
        try:
            rq = requests.get(url, headers=headers, proxies=random_proxy())
        except Exception as e:
            self.send_error_message(f"{url} - {filename}" + str(e))
        retries = 0
        while rq.status_code != 200:
            retries += 1       

            try:
                rq = requests.get(url, headers=headers, proxies=random_proxy())
            except Exception as e:
                self.send_error_message(f"{url} - {filename}" + str(e))

            if retries == 4:
                with open(filename + current_datetime, "w",
                          encoding="utf-8") as text_file:
                    text_file.write(rq.text)
                self.send_error_message("Max retries exceeded error")
                time.sleep(60)
                retries = 0

        return rq

My thought would be that this program would never fail as a result of a failed GET request, because I am wrapping every single GET request in a try catch block that should catch any exception, however, I am very occasionally getting some errors that cause the program to fail and I am not sure what I can do to stop the program from doing so.

Here is part of the the latest stack trace that caused one of my threads to fail. I could not post the whole thing, since it was well over the 30k character limit allowed by stack overflow. It over 100k in characters:

Exception in thread Thread-57720:
Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\contrib\pyopenssl.py", line 488, in wrap_socket
    cnx.do_handshake()
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\OpenSSL\SSL.py", line 1934, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\OpenSSL\SSL.py", line 1663, in _raise_ssl_error
    raise SysCallError(errno, errorcode.get(errno))
OpenSSL.SSL.SysCallError: (10053, 'WSAECONNABORTED')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 667, in urlopen
    self._prepare_proxy(conn)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 932, in _prepare_proxy
    conn.connect()
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connection.py", line 371, in connect
    ssl_context=context,
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\util\ssl_.py", line 384, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\contrib\pyopenssl.py", line 494, in wrap_socket
    raise ssl.SSLError("bad handshake: %r" % e)
ssl.SSLError: ("bad handshake: SysCallError(10053, 'WSAECONNABORTED')",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 727, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\util\retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.random_website_test_blah_blah_blah43149676132846.co.uk', port=443): Max retries exceeded with url: /sch//blah3&_sop=10&_ipg=200&rt=nc (Caused by SSLError(SSLError("bad handshake: SysCallError(10053, 'WSAECONNABORTED')")))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/user/PycharmProjects/random_website_test_blah_blah_blah43149676132846/restocks/restock_monitor.py", line 93, in request_with_error_handling
    rq = requests.get(url, headers=headers, proxies=random_proxy())
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.random_website_test_blah_blah_blah43149676132846.co.uk', port=443): Max retries exceeded with url: /sch//blah3&_sop=10&_ipg=200&rt=nc (Caused by SSLError(SSLError("bad handshake: SysCallError(10053, 'WSAECONNABORTED')")))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connection.py", line 160, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\util\connection.py", line 61, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\socket.py", line 748, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11004] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 677, in urlopen
    chunked=chunked,
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 381, in _make_request
    self._validate_conn(conn)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 978, in _validate_conn
    conn.connect()
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connection.py", line 309, in connect
    conn = self._new_conn()
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connection.py", line 172, in _new_conn
    self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x14C92E30>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 727, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\util\retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='discord.com', port=443): Max retries exceeded with url: /api/webhooks/817872766140153857/QEOUFVJSlKdCuf4suHb-J6_LvPB6-0R0Taq9IONrUxj-jWODWhBlXh0WBLNPXtS0F5hk?wait=True (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x14C92E30>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:/Users/user/PycharmProjects/random_website_test_blah_blah_blah43149676132846/restocks/restock_monitor.py", line 260, in consecutive_scrape
    page)
  File "C:/Users/user/PycharmProjects/random_website_test_blah_blah_blah43149676132846/restocks/restock_monitor.py", line 95, in request_with_error_handling
    self.send_discord_error(f"{url} - {filename}, {page}" + str(e))
  File "C:/Users/user/PycharmProjects/random_website_test_blah_blah_blah43149676132846/restocks/restock_monitor.py", line 87, in send_discord_error
    response = webhook.execute()
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord_webhook\webhook.py", line 142, in execute
    response = requests.post(url, json=self.json, proxies=self.proxies, params={'wait': True})
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\api.py", line 116, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='discord.com', port=443): Max retries exceeded with url: /api/webhooks/817872766140153857/QEOUFVJSlKdCuf4suHb-J6_LvPB6-0R0Taq9IONrUxj-jWODWhBlXh0WBLNPXtS0F5hk?wait=True (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x14C92E30>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed'))
Exception in thread Thread-57723:
Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\contrib\pyopenssl.py", line 488, in wrap_socket
    cnx.do_handshake()
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\OpenSSL\SSL.py", line 1934, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\OpenSSL\SSL.py", line 1663, in _raise_ssl_error
    raise SysCallError(errno, errorcode.get(errno))
OpenSSL.SSL.SysCallError: (10053, 'WSAECONNABORTED')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 667, in urlopen
    self._prepare_proxy(conn)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 932, in _prepare_proxy
    conn.connect()
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connection.py", line 371, in connect
    ssl_context=context,
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\util\ssl_.py", line 384, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\contrib\pyopenssl.py", line 494, in wrap_socket
    raise ssl.SSLError("bad handshake: %r" % e)
ssl.SSLError: ("bad handshake: SysCallError(10053, 'WSAECONNABORTED')",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 727, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\util\retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.random_website_test_blah_blah_blah43149676132846.co.uk', port=443): Max retries exceeded with url: /blah (Caused by SSLError(SSLError("bad handshake: SysCallError(10053, 'WSAECONNABORTED')")))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/user/PycharmProjects/random_website_test_blah_blah_blah43149676132846/restocks/restock_monitor.py", line 93, in request_with_error_handling
    rq = requests.get(url, headers=headers, proxies=random_proxy())
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='www.random_website_test_blah_blah_blah43149676132846.co.uk', port=443): Max retries exceeded with url: /blah (Caused by SSLError(SSLError("bad handshake: SysCallError(10053, 'WSAECONNABORTED')")))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connection.py", line 160, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\util\connection.py", line 61, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\socket.py", line 748, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11004] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 677, in urlopen
    chunked=chunked,
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 381, in _make_request
    self._validate_conn(conn)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 978, in _validate_conn
    conn.connect()
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connection.py", line 309, in connect
    conn = self._new_conn()
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connection.py", line 172, in _new_conn
    self, "Failed to establish a new connection: %s" % e
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x14C92890>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\connectionpool.py", line 727, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\util\retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='discord.com', port=443): Max retries exceeded with url: /api/webhooks/817872766140153857/QEOUFVJSlKdCuf4suHb-J6_LvPB6-0R0Taq9IONrUxj-jWODWhBlXh0WBLNPXtS0F5hk?wait=True (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x14C92890>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 926, in _bootstrap_inner
    self.run()
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:/Users/user/PycharmProjects/random_website_test_blah_blah_blah43149676132846/restocks/restock_monitor.py", line 260, in consecutive_scrape
    page)
  File "C:/Users/user/PycharmProjects/random_website_test_blah_blah_blah43149676132846/restocks/restock_monitor.py", line 95, in request_with_error_handling
    self.send_discord_error(f"{url} - {filename}, {page}" + str(e))
  File "C:/Users/user/PycharmProjects/random_website_test_blah_blah_blah43149676132846/restocks/restock_monitor.py", line 87, in send_discord_error
    response = webhook.execute()
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\discord_webhook\webhook.py", line 142, in execute
    response = requests.post(url, json=self.json, proxies=self.proxies, params={'wait': True})
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\api.py", line 116, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='discord.com', port=443): Max retries exceeded with url: /api/webhooks/817872766140153857/QEOUFVJSlKdCuf4suHb-J6_LvPB6-0R0Taq9IONrUxj-jWODWhBlXh0WBLNPXtS0F5hk?wait=True (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x14C92890>: Failed to establish a new connection: [Errno 11004] getaddrinfo failed'))
Exception in thread Thread-57719:
Traceback (most recent call last):
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\urllib3\contrib\pyopenssl.py", line 488, in wrap_socket
    cnx.do_handshake()
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\OpenSSL\SSL.py", line 1934, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\OpenSSL\SSL.py", line 1663, in _raise_ssl_error
    raise SysCallError(errno, errorcode.get(errno))
OpenSSL.SSL.SysCallError: (10053, 'WSAECONNABORTED')

During handling of the above exception, another exception occurred:




knowledge_seeker
  • 811
  • 1
  • 8
  • 18

1 Answers1

0

You will need to catch the error as well:

try:
    rq = requests.get(url, headers=headers, proxies=random_proxy())
except Exception as e:
    self.send_error_message(f"{url} - {filename}" + str(e))
except requests.exceptions.SSLError as er:
    self.send_error_message(f"{url} - {filename}" + str(er))

How to log error, you would need better but here are few functions that you can use to based your decision on:

er = SystemError("My error")
tr(er)
'My error'
er.args
('My error',)

UPDATE:

This is working snippet:

import requests


url = "abc"
filename = "xyz"

try:
    # rq = requests.get(url, headers=headers, proxies=random_proxy())
    raise requests.exceptions.SSLError("Handshake!")
except Exception as e:
    print(f"{url} - {filename}" + str(e))
except requests.exceptions.SSLError as er:
    print(f"{url} - {filename}" + str(er))
# Output: abc - xyzHandshake!

UPDATE 2:

Code on the GitHub

Dmytro Chasovskyi
  • 3,209
  • 4
  • 40
  • 82
  • I get an unresolved reference red underline on the ```Error``` when trying to do the ```except Error as er:```, is there anything else I need to do like import it or something? – knowledge_seeker Apr 26 '21 at 10:26
  • @user13834264 Change it to SSLError. I was thinking that there is a general `Error` but it looks like the `Error` system is slightly different in Python. See docs for more details: https://docs.python.org/3/library/exceptions.html – Dmytro Chasovskyi Apr 26 '21 at 10:30
  • @user13834264 Does it work? If not, let me know. I will write a small snippet and link it to the answer. – Dmytro Chasovskyi Apr 26 '21 at 10:37
  • I dont think it does, but according to a different thread the way of catching SSL exceptions using Python requests is like [this](https://stackoverflow.com/questions/48919078/catching-sslerror-due-to-unsecure-url-with-requests-in-python): except requests.exceptions.SSLError: – knowledge_seeker Apr 26 '21 at 10:39
  • 1
    @user13834264 Yes, it was my bad. I updated the snippet, and it actually works. – Dmytro Chasovskyi Apr 26 '21 at 10:45
  • I don't think it does actually, because the ```requests.exceptions.SSLError("Handshake!")``` error is caught by the ```except Exception as e:``` except block and not the ```except requests.exceptions.SSLError as er:``` block. In my case the ```except Exception as e:``` was not catching whatever error it was that was causing my program to fail. – knowledge_seeker Apr 26 '21 at 10:49
  • @user13834264 I see now. Can you add a full anonymized log as a file? I think that it doesn't show everything to resolve the issue. – Dmytro Chasovskyi Apr 26 '21 at 11:20
  • I think I figured out what my issue was. The ```self.send_error_message(f"{url} - {filename}" + str(e))``` is a method that makes a HTTP request in itself to notify me if an error occurs when trying to catch the main request in the event of it failing. If an error occurs in the ```self.send_error_message()``` method then the whole ```Thread``` will fail, since an exception would have occurred in the process of handling the initial exception. – knowledge_seeker Apr 26 '21 at 11:30
  • 1
    @user13834264 Great to hear! There would be no chance I could get it from the question :-D – Dmytro Chasovskyi Apr 26 '21 at 11:38