python类TooManyRedirects()的实例源码

solve.py 文件源码 项目:qlcoder 作者: L1nwatch 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def single_thread_solve():
    """
    ???????????????, ????????, ??????????
    """
    with open("solve_result.txt", "w") as f:
        check_codes = dict()
        for i in range(355, 1000 + 1):
            # ??? 1 ? 1000 ??????????
            check_code = get_verify_code(i, check_codes, f)

            # ????
            url = ("http://www.qlcoder.com/train/handsomerank?_token=d4texP05ci7veIAztvnwe5yETOFhlLWkSaBYC51B"
                   "&user=w%40tch&checkcode={}".format(check_code))

            while True:
                try:
                    response = requests.get(url, timeout=10)
                    if "?????" not in response.text:
                        print("[+] ????? {} ?".format(i), file=f)
                except (ConnectTimeout, ReadTimeout, ValueError, ConnectionError, TooManyRedirects):
                    print("[-] ??? {} ???".format(i), file=f)
                else:
                    break
models.py 文件源码 项目:bluebutton-web-server 作者: CMSgov 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def signature_verified(self):

        try:
            url = 'https://%s/.well-known/poet.jwk' % (self.iss)
            r = requests.get(url, timeout=3)

            if r.status_code == 200:
                k = json.loads(r.text)
                payload = verify_poet(self.jwt, k)
                if 'iss' in payload:
                    if payload['iss'] == k['kid']:
                        return True
        except ConnectionError:
            pass
        except TooManyRedirects:
            pass
        except Timeout:
            pass
        return False
check_connection.py 文件源码 项目:kenya-news-scrapper 作者: alfiepoleon 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def check_connection(url):
    try:
        request = requests.head(url)
        if request.status_code == 200:
            print('Connection ok...')
            return True
        elif request.status_code == 301:
            print('Connection redirect')
            return True
        else:
            print('Error connecting')
            return False
    except (ConnectionError, Timeout):
        print('{} can not be reached, check your connection and retry later'.format(url))
        return False

    except (HTTPError, TooManyRedirects):
        print('There is an issue with the url, {}, confirm it, or retry later'.format(url))
        return False
bigip_config.py 文件源码 项目:f5-aws-vpn 作者: f5devcentral 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def http(self, method, host, payload=''):
    print 'HTTP %s %s: %s' % (method, host, payload)
    methodfn = getattr(requests, method.lower(), None)
    if method is None:
      raise NotImplementedError("requests module has not method %s " % method)
    try:
      if payload != '':
        request = methodfn(url='%s/%s' % (self.hosturl, host), data=json.dumps(payload), auth=self.auth, verify=False)
      else:
        request = methodfn(url='%s/%s' % (self.hosturl, host), auth=self.auth, verify=False)

      if request.status_code != requests.codes.ok:
        request.raise_for_status()

      rc = 0
      out = json.loads(request.text)
      err = ''
    except (ConnectionError, HTTPError, Timeout, TooManyRedirects) as e:
      rc = 1
      out = ''
      err = '%s. Error received: %s.\n Sent request: %s' % (
          e.message, json.loads(request.text), 'HTTP %s %s: %s' % (method, host, payload))

    print 'HTTP %s returned: %s' % (method, request.text)

    return (rc, out, err)
test_client.py 文件源码 项目:python-kemptech-api 作者: KEMPtechnologies 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def test_re_raised_exceptions(self):
        my_exceptions = (exceptions.ConnectionError,
                                     exceptions.URLRequired,
                                     exceptions.TooManyRedirects,
                                     exceptions.Timeout,
                                     exceptions.RequestException)
        for e in my_exceptions:
            self.response.raise_for_status.side_effect = e
            with assert_raises(e):
                self.client._do_request('GET','MyCommand')
web_util.py 文件源码 项目:wechannel 作者: PegasusWang 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def retry(retries=CONFIG.CRAWLER.RETRY or 3, sleep=CONFIG.CRAWLER.SLEEP,
          changeip=False):
    """??????????????????????retrying
    pip install retrying
    https://github.com/rholder/retrying
    ??????????
    http://mp.weixin.qq.com/s?__biz=MzAwMDU1MTE1OQ==&mid=2653547274&idx=1&sn=52e5037b163146c1656eedce2da1ecd8&scene=1&srcid=0527MEXhNRZATtlTPhinD5Re#rd

    :param retries: number int of retry times.
    301 Moved Temporarily
    401 Unauthorized
    403 Forbidden
    404 Not Found
    408 Request Timeout
    429 Too Many Requests
    503 Service Unavailable
    """
    def _retry(func):
        @wraps(func)
        def _wrapper(*args, **kwargs):
            index = 0
            while index < retries:
                index += 1
                try:
                    response = func(*args, **kwargs)
                    if response.status_code in (301, 302, 404, 500):
                        print('status_code', response.status_code)
                        break
                    elif response.status_code != 200:
                        print(response.status_code)
                        if changeip:
                            change_ip()
                        continue
                    else:
                        break
                except Exception as e:
                    # ???????????
                    # traceback.print_exc()
                    response = None
                    if isinstance(e, Timeout):
                        if sleep is not None:
                            time.sleep(sleep + randint(1, 10))
                        continue
                    elif isinstance(e, TooManyRedirects):
                        break

            return response
        return _wrapper
    return _retry


问题


面经


文章

微信
公众号

扫码关注公众号