Reduce logging verbosity for socks.GeneralProxyError

This commit is contained in:
Lee Miller 2023-05-29 00:19:02 +03:00
parent 4c63a1be40
commit b26cf7322d
Signed by untrusted user: lee.miller
GPG Key ID: 4F97A5EA88F4AB63
1 changed files with 11 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import errno
import logging
import math
import random
import re
import select
import socket
import ssl
@ -163,8 +164,17 @@ class Connection(threading.Thread):
except socket.timeout:
pass
except OSError as e:
try: # possible socks.GeneralProxyError
e = e.socket_err
if isinstance(e, socket.timeout) or (
# general failure, unreachable, refused
not e.errno and re.match(r'^0x0[1,4,5].*', e.msg)
):
e.errno = 0
except AttributeError:
pass
# unreachable, refused, no route
(logging.info if e.errno not in (101, 111, 113)
(logging.info if e.errno not in (0, 101, 111, 113)
else logging.debug)(
'Connection to %s failed. Reason: %s', peer_str, e)
except Exception: