{"record":{"id":"5982d87d3be4332c","repo":"ArchiveBox/ArchiveBox","slug":"tried-to-parse-invalid-date-date","errorCode":null,"errorMessage":"Tried to parse invalid date! {date}","messagePattern":"Tried to parse invalid date! (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"archivebox/misc/util.py","lineNumber":421,"sourceCode":"            pass\n\n        try:\n            iso_date = normalized.replace(\"Z\", \"+00:00\")\n            parsed_date = datetime.fromisoformat(iso_date)\n            if parsed_date.tzinfo is None:\n                return parsed_date.replace(tzinfo=timezone.utc)\n            return parsed_date.astimezone(timezone.utc)\n        except ValueError:\n            pass\n\n        from dateparser import parse as dateparser\n\n        parsed_date = dateparser(normalized, settings={\"TIMEZONE\": \"UTC\"})\n        if parsed_date is None:\n            raise ValueError(f\"Tried to parse invalid date string! {date}\")\n        return parsed_date.astimezone(timezone.utc)\n\n    raise ValueError(f\"Tried to parse invalid date! {date}\")\n\n\n@enforce_types\ndef download_url(url: str, timeout: int | None = None, config=None, **config_kwargs) -> str:\n    \"\"\"Download the contents of a remote url and return the text\"\"\"\n\n    import requests\n    from w3lib.encoding import html_body_declared_encoding, http_content_type_encoding\n\n    from archivebox.config.common import get_config\n\n    config = config or get_config(**config_kwargs)\n    timeout = timeout or config.TIMEOUT\n    session = requests.Session()\n\n    if config.COOKIES_FILE and Path(config.COOKIES_FILE).is_file():\n        cookie_jar = http.cookiejar.MozillaCookieJar(config.COOKIES_FILE)\n        cookie_jar.load(ignore_discard=True, ignore_expires=True)","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/ArchiveBox/ArchiveBox/blob/74564b28220090664f919479e82cbf454125fa34/archivebox/misc/util.py#L403-L439","documentation":"parse_date in archivebox/misc/util.py raises ValueError when the incoming value cannot be normalized into a datetime. There are two failure points: the value is not a str/int/datetime (falls to the final raise at line 421), or dateparser returns None for an unparseable string (the \"invalid date string\" raise). Callers like from_json, RSS parsing, and directory imports pass user- or external-supplied timestamps, so malformed input surfaces here.","triggerScenarios":"Calling parse_date with a non-date string (e.g. 'N/A', empty string, a URL), a numeric type other than int/float epoch, or a datetime subclass handled upstream; also any string dateparser cannot interpret under UTC settings.","commonSituations":"Importing bookmarks/exports where a timestamp field is missing or filled with placeholder text; RSS feeds with malformed pubDates; JSON snapshots saved by older ArchiveBox versions with different date formats; passing a float epoch instead of int.","solutions":["Inspect the {date} value in the message and fix the source data so it is a valid date string, int epoch, or datetime.","Pre-validate with dateparser in the caller and skip or default entries whose date is None before calling parse_date.","If epoch input, ensure it is an int (not float or numeric string); convert numeric strings with int()/float() first.","Wrap calls in try/except ValueError when processing untrusted bulk imports so one bad record does not abort the run."],"exampleFix":"// before\nsnapshot['timestamp'] = parse_date(row['saved_at'])\n// after\nraw = (row.get('saved_at') or '').strip()\nsnapshot['timestamp'] = parse_date(raw) if raw and dateparser.parse(raw) else None","handlingStrategy":"validation","validationCode":"from dateparser import parse\ndef is_parseable_date(value) -> bool:\n    return isinstance(value, (int,)) or (isinstance(value, str) and bool(parse(value)))","typeGuard":"def is_date_input(v) -> bool:\n    return isinstance(v, (int, str)) and (isinstance(v, int) or parse(v) is not None)","tryCatchPattern":"try:\n    dt = parse_date(raw)\nexcept ValueError as e:\n    log.warning(\"bad date: %s\", e); dt = None","preventionTips":["Sanitize timestamps at import boundaries; drop or default placeholders like 'N/A' or ''.","Store epochs as int, not float or numeric strings.","Unit-test date parsing against all export formats you ingest."],"tags":["python","valueerror","date-parsing","input-validation"],"backgroundTag":"invalid-date-string","analyzedSha":"74564b28220090664f919479e82cbf454125fa34","analyzedAt":"2026-08-28T23:56:51.556Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}