当前位置: 首页>>代码示例>>Python>>正文


Python parser.error方法代码示例

本文整理汇总了Python中dateutil.parser.error方法的典型用法代码示例。如果您正苦于以下问题:Python parser.error方法的具体用法?Python parser.error怎么用?Python parser.error使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dateutil.parser的用法示例。


在下文中一共展示了parser.error方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post_scihub

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import error [as 别名]
def post_scihub(url, query, user, password):
    """
    Send a POST request to scihub.
    """
    r = requests.post(url, dict(q=query), auth=(user, password))
    if r.ok:
        return r
    else:
        print('ERROR:', end=' ')
        if r.status_code == 503:
            print('The Sentinels Scientific Data Hub is down. Check on'
                  ' https://scihub.copernicus.eu/dhus/#/home')
        elif r.status_code == 401:
            print('Authentication failed with', user, password)
        else:
            print('Scientific Data Hub returned error', r.status_code)
        r.raise_for_status() 
开发者ID:cmla,项目名称:tsd,代码行数:19,代码来源:search_scihub.py

示例2: handle_exception

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import error [as 别名]
def handle_exception(exc_type, exc_value, exc_traceback):
    if state.session:
        state.session.save()
    if issubclass(exc_type, KeyboardInterrupt):
        sys.__excepthook__(exc_type, exc_value, exc_traceback)
        return

    logger.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback)) 
开发者ID:tonycpsu,项目名称:mlbstreamer,代码行数:10,代码来源:play.py

示例3: get_params

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import error [as 别名]
def get_params():
    parser = get_params_parser()
    args = parser.parse_args()

    if not args.org or not args.token:
        parser.error("token and org params must be provided.")
        sys.exit(1)

    return args 
开发者ID:chaoss,项目名称:grimoirelab-elk,代码行数:11,代码来源:gh2arthur.py

示例4: get_repositores

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import error [as 别名]
def get_repositores(owner_url, token, nrepos):
    """ owner could be an org or and user """
    all_repos = []

    url = owner_url

    while True:
        logging.debug("Getting repos from: %s" % (url))
        try:
            r = requests.get(url,
                             params=get_payload(),
                             headers=get_headers(token))

            r.raise_for_status()
            all_repos += r.json()

            logging.debug("Rate limit: %s" % (r.headers['X-RateLimit-Remaining']))

            if 'next' not in r.links:
                break

            url = r.links['next']['url']  # Loving requests :)
        except requests.exceptions.ConnectionError:
            logging.error("Can not connect to GitHub")
            break

    # Remove forks
    nrepos_recent = [repo for repo in all_repos if not repo['fork']]
    # Sort by updated_at and limit to nrepos
    nrepos_sorted = sorted(nrepos_recent, key=lambda repo: parser.parse(repo['updated_at']), reverse=True)
    if nrepos > 0:
        nrepos_sorted = nrepos_sorted[0:nrepos]
    # First the small repositories to feedback the user quickly
    nrepos_sorted = sorted(nrepos_sorted, key=lambda repo: repo['size'])
    for repo in nrepos_sorted:
        logging.debug("%s %i %s" % (repo['updated_at'], repo['size'], repo['name']))
    return nrepos_sorted 
开发者ID:chaoss,项目名称:grimoirelab-elk,代码行数:39,代码来源:gh2arthur.py

示例5: get_repositores

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import error [as 别名]
def get_repositores(owner_url, token, nrepos):
    """ owner could be an org or and user """
    all_repos = []

    url = owner_url

    while True:
        logging.debug("Getting repos from: %s" % (url))
        try:
            r = requests.get(url,
                             params=get_payload(),
                             headers=get_headers(token))

            r.raise_for_status()
            all_repos += r.json()

            logging.debug("Rate limit: %s" % (r.headers['X-RateLimit-Remaining']))

            if 'next' not in r.links:
                break

            url = r.links['next']['url']  # Loving requests :)
        except requests.exceptions.ConnectionError:
            logging.error("Can not connect to GitHub")
            break

    # Remove forks
    nrepos_recent = [repo for repo in all_repos if not repo['fork']]
    # Sort by updated_at and limit to nrepos
    nrepos_sorted = sorted(nrepos_recent, key=lambda repo: parser.parse(repo['updated_at']), reverse=True)
    nrepos_sorted = nrepos_sorted[0:nrepos]
    # First the small repositories to feedback the user quickly
    nrepos_sorted = sorted(nrepos_sorted, key=lambda repo: repo['size'])
    for repo in nrepos_sorted:
        logging.debug("%s %i %s" % (repo['updated_at'], repo['size'], repo['name']))
    return nrepos_sorted 
开发者ID:chaoss,项目名称:grimoirelab-elk,代码行数:38,代码来源:gh2k.py

示例6: create_redirect_web_page

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import error [as 别名]
def create_redirect_web_page(web_dir, org_name, kibana_url):
    """ Create HTML pages with the org name that redirect to
        the Kibana dashboard filtered for this org """
    html_redirect = """
    <html>
        <head>
    """
    html_redirect += """<meta http-equiv="refresh" content="0; URL=%s/app/kibana"""\
                     % kibana_url
    html_redirect += """#/dashboard/Overview?_g=(filters:!(('$state':"""
    html_redirect += """(store:globalState),meta:(alias:!n,disabled:!f,index:"""
    html_redirect += """github_git_enrich,key:project,negate:!f,value:%s),"""\
                     % org_name
    html_redirect += """query:(match:(project:(query:%s,type:phrase))))),"""\
                     % org_name
    html_redirect += """refreshInterval:(display:Off,pause:!f,value:0),"""
    html_redirect += """time:(from:now-2y,mode:quick,to:now))" />
        </head>
    </html>
    """
    try:
        with open(path.join(web_dir, org_name), "w") as f:
            f.write(html_redirect)
    except FileNotFoundError as ex:
        logging.error("Wrong web dir for redirect pages: %s" % (web_dir))
        logging.error(ex) 
开发者ID:chaoss,项目名称:grimoirelab-elk,代码行数:28,代码来源:gh2k.py

示例7: poll_activation

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import error [as 别名]
def poll_activation(asset):
    """
    Wait for an asset, requested to Planet data API, to be ready for download.

    Args:
        asset (dict): dictionary containing the asset info

    Return:
        (string): url to the file ready for download
    """
    # refresh the asset info
    r = requests.get(asset['_links']['_self'], auth=(os.environ['PL_API_KEY'], ''))
    if r.ok:
        asset = r.json()
    elif r.status_code == 429:  # rate limit
        time.sleep(1)
        return poll_activation(asset)
    else:
        print('ERROR: got {} error code when requesting {}'.format(r.status_code,
                                                                   asset['_links']['_self']))
        return

    # decide what to do next depending on the asset status
    if asset['status'] == 'active':
        return asset['location']
    elif asset['status'] == 'activating':
        time.sleep(3)
        return poll_activation(asset)
    elif asset['status'] == 'inactive':
        request_activation(asset)
        time.sleep(3)
        return poll_activation(asset)
    else:
        print('ERROR: unknown asset status {}'.format(asset['status'])) 
开发者ID:cmla,项目名称:tsd,代码行数:36,代码来源:get_planet.py

示例8: request_clip

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import error [as 别名]
def request_clip(item, asset, aoi, active=False):
    """
    Request a clip to Planet clip & ship API.

    Args:
        item (dict): dictionary containing the item info
        asset (dict): dictionary containing the asset info
        aoi (dict): dictionary containing a geojson polygon (e.g. output of
            utils.geojson_geometry_object)
        active (bool): boolean

    Return:
        (dict): dictionary containing the clip info
    """
    if not active:  # wait for the asset to be actived
        poll_activation(asset)

    # request the clip
    d = {
        "aoi": aoi,
        "targets": [
            {
                "item_id": item['id'],
                "item_type": item['properties']['item_type'],
                "asset_type": asset['type']
            }
        ]
    }
    headers = {'content-type': 'application/json'}
    r = requests.post(CAS_URL,
                      headers=headers, data=json.dumps(d),
                      auth=(os.environ['PL_API_KEY'], ''))
    if r.ok:
        return r.json()
    elif r.status_code == 429:  # rate limit
        time.sleep(1)
        return request_clip(item, asset, aoi, active=True)
    else:
        print('ERROR: got {} error code when requesting {}'.format(r.status_code, d)) 
开发者ID:cmla,项目名称:tsd,代码行数:41,代码来源:get_planet.py

示例9: poll_clip

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import error [as 别名]
def poll_clip(clip_json):
    """
    Wait for a clip, requested to Planet clip & ship API, to be ready.

    Args:
        clip_json (dict): dictionary containing the clip info

    Return:
        (string): url to the zipfile containing the clipped data.
    """
    # refresh the clip info
    clip_request_url = clip_json['_links']['_self']
    r = requests.get(clip_request_url, auth=(os.environ['PL_API_KEY'], ''))
    if r.ok:
        j = r.json()
    elif r.status_code == 429:  # rate limit
        time.sleep(1)
        return poll_clip(clip_json)
    else:
        print('ERROR: got {} error code when requesting {}'.format(r.status_code, clip_request_url))
        return

    # decide what to do next depending on the clip status
    if j['state'] == 'succeeded':
        return j['_links']['results'][0]
    elif j['state'] == 'running':
        time.sleep(3)
        return poll_clip(clip_json)
    else:
        print('ERROR: unknown state "{}" of clip request {}'.format(j['state'],
                                                                    clip_request_url)) 
开发者ID:cmla,项目名称:tsd,代码行数:33,代码来源:get_planet.py

示例10: invoke

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import error [as 别名]
def invoke(self, function_name, raw_python=False, command=None, no_color=False):
        """
        Invoke a remote function.
        """

        # There are three likely scenarios for 'command' here:
        #   command, which is a modular function path
        #   raw_command, which is a string of python to execute directly
        #   manage, which is a Django-specific management command invocation
        key = command if command is not None else 'command'
        if raw_python:
            command = {'raw_command': function_name}
        else:
            command = {key: function_name}

        # Can't use hjson
        import json as json

        response = self.zappa.invoke_lambda_function(
            self.lambda_name,
            json.dumps(command),
            invocation_type='RequestResponse',
        )

        if 'LogResult' in response:
            if no_color:
                print(base64.b64decode(response['LogResult']))
            else:
                decoded = base64.b64decode(response['LogResult']).decode()
                formatted = self.format_invoke_command(decoded)
                colorized = self.colorize_invoke_command(formatted)
                print(colorized)
        else:
            print(response)

        # For a successful request FunctionError is not in response.
        # https://github.com/Miserlou/Zappa/pull/1254/
        if 'FunctionError' in response:
            raise ClickException(
                "{} error occurred while invoking command.".format(response['FunctionError'])
) 
开发者ID:Miserlou,项目名称:Zappa,代码行数:43,代码来源:cli.py

示例11: check_stage_name

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import error [as 别名]
def check_stage_name(self, stage_name):
        """
        Make sure the stage name matches the AWS-allowed pattern

        (calls to apigateway_client.create_deployment, will fail with error
        message "ClientError: An error occurred (BadRequestException) when
        calling the CreateDeployment operation: Stage name only allows
        a-zA-Z0-9_" if the pattern does not match)
        """
        if self.stage_name_env_pattern.match(stage_name):
            return True
        raise ValueError("AWS requires stage name to match a-zA-Z0-9_") 
开发者ID:Miserlou,项目名称:Zappa,代码行数:14,代码来源:cli.py

示例12: handle

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import error [as 别名]
def handle(): # pragma: no cover
    """
    Main program execution handler.
    """

    try:
        cli = ZappaCLI()
        sys.exit(cli.handle())
    except SystemExit as e: # pragma: no cover
        cli.on_exit()
        sys.exit(e.code)

    except KeyboardInterrupt: # pragma: no cover
        cli.on_exit()
        sys.exit(130)
    except Exception as e:
        cli.on_exit()

        click.echo("Oh no! An " + click.style("error occurred", fg='red', bold=True) + "! :(")
        click.echo("\n==============\n")
        import traceback
        traceback.print_exc()
        click.echo("\n==============\n")
        shamelessly_promote()

        sys.exit(-1) 
开发者ID:Miserlou,项目名称:Zappa,代码行数:28,代码来源:cli.py

示例13: get_opts

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import error [as 别名]
def get_opts(args=None):
    parser = argparse.ArgumentParser()
    parser.add_argument(
        '--max-run-time',
        type=timedelta_type,
        help="Maximum time a container is allows to run. Time may "
        "be specified in any pytimeparse supported format."
    )
    parser.add_argument(
        '--prefix', action="append", default=[],
        help="Only stop containers which match one of the "
             "prefix."
    )
    parser.add_argument(
        '--dry-run', action="store_true",
        help="Only log actions, don't stop anything."
    )
    parser.add_argument(
        '-t', '--timeout', type=int, default=60,
        help="HTTP timeout in seconds for making docker API calls."
    )
    opts = parser.parse_args(args=args)

    if not opts.prefix:
        parser.error("Running with no --prefix will match nothing.")

    return opts 
开发者ID:Yelp,项目名称:docker-custodian,代码行数:29,代码来源:docker_autostop.py

示例14: touch_endpoint

# 需要导入模块: from dateutil import parser [as 别名]
# 或者: from dateutil.parser import error [as 别名]
def touch_endpoint(self, endpoint_url):
        """
        Test the deployed endpoint with a GET request.
        """

        # Private APIGW endpoints most likely can't be reached by a deployer
        # unless they're connected to the VPC by VPN. Instead of trying
        # connect to the service, print a warning and let the user know
        # to check it manually.
        # See: https://github.com/Miserlou/Zappa/pull/1719#issuecomment-471341565
        if 'PRIVATE' in self.stage_config.get('endpoint_configuration', []):
            print(
                click.style("Warning!", fg="yellow", bold=True) +
                " Since you're deploying a private API Gateway endpoint,"
                " Zappa cannot determine if your function is returning "
                " a correct status code. You should check your API's response"
                " manually before considering this deployment complete."
            )
            return

        touch_path = self.stage_config.get('touch_path', '/')
        req = requests.get(endpoint_url + touch_path)

        # Sometimes on really large packages, it can take 60-90 secs to be
        # ready and requests will return 504 status_code until ready.
        # So, if we get a 504 status code, rerun the request up to 4 times or
        # until we don't get a 504 error
        if req.status_code == 504:
            i = 0
            status_code = 504
            while status_code == 504 and i <= 4:
                req = requests.get(endpoint_url + touch_path)
                status_code = req.status_code
                i += 1

        if req.status_code >= 500:
            raise ClickException(click.style("Warning!", fg="red", bold=True) +
                " Status check on the deployed lambda failed." +
                " A GET request to '" + touch_path + "' yielded a " +
                click.style(str(req.status_code), fg="red", bold=True) + " response code.")

####################################################################
# Main
#################################################################### 
开发者ID:Miserlou,项目名称:Zappa,代码行数:46,代码来源:cli.py


注:本文中的dateutil.parser.error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。