Python dateutil.parser.error() Examples
The following are 15
code examples of dateutil.parser.error().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
dateutil.parser
, or try the search function
.
Example #1
Source File: search_scihub.py From tsd with GNU Affero General Public License v3.0 | 6 votes |
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()
Example #2
Source File: play.py From mlbstreamer with GNU General Public License v2.0 | 5 votes |
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))
Example #3
Source File: gh2arthur.py From grimoirelab-elk with GNU General Public License v3.0 | 5 votes |
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
Example #4
Source File: gh2arthur.py From grimoirelab-elk with GNU General Public License v3.0 | 5 votes |
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
Example #5
Source File: gh2k.py From grimoirelab-elk with GNU General Public License v3.0 | 5 votes |
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
Example #6
Source File: gh2k.py From grimoirelab-elk with GNU General Public License v3.0 | 5 votes |
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
Example #7
Source File: gh2k.py From grimoirelab-elk with GNU General Public License v3.0 | 5 votes |
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)
Example #8
Source File: get_planet.py From tsd with GNU Affero General Public License v3.0 | 5 votes |
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']))
Example #9
Source File: get_planet.py From tsd with GNU Affero General Public License v3.0 | 5 votes |
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))
Example #10
Source File: get_planet.py From tsd with GNU Affero General Public License v3.0 | 5 votes |
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))
Example #11
Source File: cli.py From Zappa with MIT License | 5 votes |
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']) )
Example #12
Source File: cli.py From Zappa with MIT License | 5 votes |
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_")
Example #13
Source File: cli.py From Zappa with MIT License | 5 votes |
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)
Example #14
Source File: docker_autostop.py From docker-custodian with Apache License 2.0 | 5 votes |
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
Example #15
Source File: cli.py From Zappa with MIT License | 4 votes |
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 ####################################################################