Projects STRLCPY got-your-back Commits 139a4835
🤬
  • ■ ■ ■ ■ ■ ■
    gyb.py
    skipped 47 lines
    48 48  import os.path
    49 49  import ipaddress
    50 50  import multiprocessing
    51  -from socket import gethostbyname
    52 51  from urllib.parse import urlencode, urlparse, parse_qs
    53 52  import wsgiref.simple_server
    54 53  import wsgiref.util
    skipped 661 lines
    716 715   e = e.args[0]
    717 716   systemErrorExit(5, e)
    718 717   
     718 +def _backoff(n, retries, reason):
     719 + wait_on_fail = (2 ** n) if (2 ** n) < 60 else 60
     720 + randomness = float(random.randint(1,1000)) / 1000
     721 + wait_on_fail += randomness
     722 + if n > 3:
     723 + sys.stderr.write('\nTemp error %s. Backing off %s seconds...'
     724 + % (reason, int(wait_on_fail)))
     725 + time.sleep(wait_on_fail)
     726 + if n > 3:
     727 + sys.stderr.write('attempt %s/%s\n' % (n+1, retries))
     728 + 
    719 729  def callGAPI(service, function, soft_errors=False, throw_reasons=[], retry_reasons=[], **kwargs):
    720 730   retries = 10
    721 731   parameters = kwargs.copy()
    skipped 15 lines
    737 747   return
    738 748   else:
    739 749   sys.exit(int(http_status))
     750 + except (OSError,
     751 + socket.timeout,
     752 + socket.gaierror,
     753 + ssl.SSLEOFError,
     754 + httplib2.error.ServerNotFoundError) as e:
     755 + _backoff(n, retries, e)
     756 + continue
    740 757   except googleapiclient.errors.HttpError as e:
    741 758   try:
    742 759   error = json.loads(e.content.decode('utf-8'))
    skipped 9 lines
    752 769   if n != retries and (http_status >= 500 or
    753 770   reason in ['rateLimitExceeded', 'userRateLimitExceeded', 'backendError'] or
    754 771   reason in retry_reasons):
    755  - wait_on_fail = (2 ** n) if (2 ** n) < 60 else 60
    756  - randomness = float(random.randint(1,1000)) / 1000
    757  - wait_on_fail += randomness
    758  - if n > 3:
    759  - sys.stderr.write('\nTemp error %s. Backing off %s seconds...'
    760  - % (reason, int(wait_on_fail)))
    761  - time.sleep(wait_on_fail)
    762  - if n > 3:
    763  - sys.stderr.write('attempt %s/%s\n' % (n+1, retries))
    764  - continue
     772 + _backoff(n, retries, reason)
     773 + continue
    765 774   sys.stderr.write('\n%s: %s - %s\n' % (http_status, message, reason))
    766 775   if soft_errors:
    767 776   sys.stderr.write(' - Giving up.\n')
    skipped 93 lines
    861 870   # find a way to support IPv6 here and get preferred IP
    862 871   # note that IPv6 may be broken on some systems also :-(
    863 872   # for now IPv4 should do.
    864  - local_ip = gethostbyname('localhost')
     873 + local_ip = socket.gethostbyname('localhost')
    865 874   local_ipaddress = ipaddress.ip_address(local_ip)
    866 875   ip4_local_range = ipaddress.ip_network('127.0.0.0/8')
    867 876   ip6_local_range = ipaddress.ip_network('::1/128')
    skipped 867 lines
    1735 1744   INSERT INTO labels (message_num, label) VALUES (?, ?)""",
    1736 1745   (message_num, label))
    1737 1746   
    1738  -def _createHttpObj(cache=None, timeout=None):
     1747 +def _createHttpObj(cache=None, timeout=600):
    1739 1748   http_args = {'cache': cache, 'timeout': timeout}
    1740 1749   if 'tls_maximum_version' in options:
    1741 1750   http_args['tls_maximum_version'] = options.tls_maximum_version
    skipped 921 lines
Please wait...
Page is in error, reload to recover