1

So today I was using a script I wrote myself where I noticed that something was wrong. I ran my program with using multiprocessing for few hours and then I got hit with different errors.

The first one is:

Problem1

The second one is:

Problem2

The last one:

Traceback (most recent call last):
    self.wrapped.write(text[start:end])
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 40, in write
    self.__convertor.write(text)
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 141, in write
    self.write_and_convert(text)
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 169, in write_and_convert
      File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 40, in write
    self.__convertor.write(text)
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 141, in write
    self.write_and_convert(text)
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 169, in write_and_convert
    self.write_plain_text(text, cursor, len(text))  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 174, in write_plain_text
    self.wrapped.write(text[start:end])
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 40, in write
    self.__convertor.write(text)
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 141, in write
    self.write_and_convert(text)
    self.wrapped.write(text[start:end])
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 40, in write
    self.__convertor.write(text)
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 141, in write
    self.write_and_convert(text)
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 169, in write_and_convert
      File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 169, in write_and_convert
    self.write_plain_text(text, cursor, len(text))
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 174, in write_plain_text
    self.wrapped.write(text[start:end])
  File "C:\Program Files\Python36\lib\site-packages\colorama\ansitowin32.py", line 40, in write
    self.__convertor.write(text)

The problem is that I tried to search for all these three problems where I didnt really found information for Python but I want to ask you guys what does errors means which I can learn what they do and also I also want to know how I would be possible able to avoid them/or retry if it hits with try - except I assume?

Similar stuff what I do is following:

logger = Logger(value)
    while True:

        try:
            url = 'https://www.google.com'

            headers = {
                'User-Agent': ('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36'
                               ' (KHTML, like Gecko) Chrome/68.0.3440.75 Safari/537.36')
            }

            requests.packages.urllib3.disable_warnings()
            resp = requests.get(url, headers=headers, verify=False, proxies=get_random_proxy(), timeout=12)
            resp.raise_for_status()

            if resp.status_code == 200 or 301:
                return resp.url

        except HTTPError as err:
            randomtime = random.randint(0, 1)
            logger.error('Error HTTPError! -  Retrying in {} secs'.format(randomtime))
            time.sleep(randomtime)
            continue


        except requests.exceptions.ConnectionError as err:
            randomtime = random.randint(0, 1)
            logger.error('Error ConnectionError proxy! -  Retrying in {} secs'.format(randomtime))
            time.sleep(randomtime)
            continue

        except requests.exceptions.RequestException as err:
            randomtime = random.randint(0, 1)
            logger.error('Request error proxy! - Retrying in {} secs'.format(randomtime))
            time.sleep(randomtime)
            continue

        except ssl.SSLWantWriteError:
            randomtime = random.randint(0, 1)
            logger.error('SSL Write Error! - Retrying in {} secs'.format(randomtime))
            time.sleep(randomtime)
            continue

        except ssl.SSLError as err:
            randomtime = random.randint(0, 1)
            logger.error('SSL ERROR!\n {} - Retrying in {} secs'.format(err, randomtime))
            time.sleep(randomtime)
            continue

My guess to not getting these error is maybet o do something like

except ConnectionRefusedError as err:
    randomtime = random.randint(0, 1)
    logger.error('ERROR!\n {} - Retrying in {} secs'.format(err, randomtime))
    time.sleep(randomtime)
    continue

except request.exceptions.ProxyError as err:
    randomtime = random.randint(0, 1)
    logger.error('ERROR!\n {} - Retrying in {} secs'.format(err, randomtime))
    time.sleep(randomtime)
    continue

Im not sure but I would appreciate for anything. Anything would be appreciated!

Hellosiroverthere
  • 285
  • 10
  • 19
  • If you're getting `ConnectionRefusedError` or `ProxyError`, simply trying again is very unlikely to work. Those errors mean something is actually _wrong_, and will have to be fixed. – John Gordon Nov 23 '18 at 19:50
  • In which way could they be wrong if I might ask and what are you suggestions basically to solve it? @JohnGordon – Hellosiroverthere Nov 23 '18 at 19:53
  • 1
    `ConnectionRefusedError` means that the remote host can't, or doesn't want to, answer your request. Fixing it would depend on _why_ the host isn't answering. Maybe you're trying to connect on the wrong port number, in which case the fix is obvious -- use the correct port number. Or maybe the host is configured to reject requests from your IP address, in which case there's nothing you can do. – John Gordon Nov 23 '18 at 20:01
  • Oh so that means at the end that it could be an Proxy that can be causing it aswell that made the connectionRefusedError to actually happend? – Hellosiroverthere Nov 23 '18 at 20:05
  • I don't know a lot about proxies; I suppose it could happen that way. – John Gordon Nov 23 '18 at 20:06
  • Alright I will try give it a go with changing maybe proxies inside a try except incase and see if it causes an issue again. – Hellosiroverthere Nov 23 '18 at 20:08
  • Also a suggestion or more likely a question. Is it bad to just do `except Exception` ? @JohnGordon – Hellosiroverthere Nov 23 '18 at 20:10
  • If you're handling all exceptions the same, then that's an okay way to do it. – John Gordon Nov 23 '18 at 20:43

1 Answers1

2

Was having a similar issue, tried to catch it with the exception from builtins:

from builtins import ConnectionRefusedError

which seemed like the most obvious solution, however the following worked:

requests.exceptions.ConnectionError

see here

cardamom
  • 6,873
  • 11
  • 48
  • 102