{"record":{"id":"0f3d8d6ff4b700fd","repo":"pypa/pip","slug":"error-reading-pylock-file-pylock-path-or-url-r","errorCode":null,"errorMessage":"Error reading pylock file {pylock_path_or_url!r}: {exc}","messagePattern":"Error reading pylock file (.+?): (.+?)","errorType":"exception","errorClass":"InstallationError","httpStatus":null,"severity":"error","filePath":"src/pip/_internal/utils/pylock.py","lineNumber":281,"sourceCode":"    # Assume this is a bare path.\n    return Path(path_or_url).read_text(encoding=\"utf-8\")\n\n\ndef select_from_pylock_path_or_url(\n    pylock_path_or_url: str,\n    session: PipSession,\n) -> Iterator[\n    tuple[\n        Package,\n        PackageVcs | PackageDirectory | PackageArchive | PackageWheel | PackageSdist,\n    ]\n]:\n    try:\n        pylock_content = _get_pylock_path_or_url_content(pylock_path_or_url, session)\n    except DiagnosticPipError:\n        raise\n    except Exception as exc:\n        raise InstallationError(\n            f\"Error reading pylock file {pylock_path_or_url!r}: {exc}\"\n        ) from exc\n\n    try:\n        lock = Pylock.from_dict(tomllib.loads(pylock_content))\n    except Exception as exc:\n        raise InstallationError(\n            f\"Invalid pylock file {pylock_path_or_url!r}: {exc}\"\n        ) from exc\n\n    try:\n        # TODO: for completeness, pylock.select should support preferring sdist\n        # over wheels to support --no-binary\n        yield from lock.select()\n    except Exception as exc:\n        raise InstallationError(\n            f\"Cannot select requirements from pylock file {pylock_path_or_url!r}: {exc}\"\n        ) from exc","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/pypa/pip/blob/f399c3718970b1b0e2478dac5296eb62679a9b86/src/pip/_internal/utils/pylock.py#L263-L299","documentation":"Raised as InstallationError by select_from_pylock_path_or_url (pylock.py:281) when the pylock file content cannot be fetched or read. This wraps any non-DiagnosticPipError exception from _get_pylock_path_or_url_content, which handles HTTP fetches (session.get), file:// reads, and local file reads via Path.read_text. The original exception is chained via `from exc`. Common underlying causes: network errors, HTTP 404/403, file not found, permission denied.","triggerScenarios":"Calling select_from_pylock_path_or_url with a path_or_url that cannot be read: a dead HTTP link (lines 259-260 raise_for_status), a file:// URL to a missing file, or a local path that doesn't exist (Path.read_text at line 264). The except at line 280 catches it and re-raises as InstallationError.","commonSituations":"Typo in the pylock URL or path. The lock file was deleted or moved. Network connectivity issues or proxy/firewall blocking the request. HTTP authentication required but not provided. Permission denied on a local file.","solutions":["Verify the pylock URL/path is correct and accessible (open it in a browser or check with curl).","For HTTP sources, ensure authentication and network access: set PIP_INDEX_URL, credentials, or proxy env vars as needed.","For local paths, verify the file exists and is readable (`ls -la <path>`).","Re-download or regenerate the pylock file if it was lost or corrupted."],"exampleFix":"// before\npip install -r https://broken.example.com/missing.toml\n\n// after\npip install -r https://correct.example.com/pylock.toml","handlingStrategy":"try-catch","validationCode":"from urllib.parse import urlsplit\nfrom pathlib import Path\n\ndef pylock_source_readable(path_or_url: str) -> bool:\n    \"\"\"Quick pre-check that a pylock source can be read.\"\"\"\n    scheme = urlsplit(path_or_url).scheme\n    if scheme in ('http', 'https', 'file'):\n        import urllib.request\n        try:\n            urllib.request.urlopen(path_or_url, timeout=5)\n            return True\n        except Exception:\n            return False\n    return Path(path_or_url).is_file()","typeGuard":null,"tryCatchPattern":"from pip._internal.exceptions import InstallationError\n\ntry:\n    from pip._internal.utils.pylock import select_from_pylock_path_or_url\n    # select_from_pylock_path_or_url(path_or_url, session)\nexcept InstallationError as e:\n    if 'Error reading pylock file' in str(e):\n        # handle I/O / network failure: retry, fix URL, or fall back\n        pass","preventionTips":["Verify URLs resolve before referencing them in install commands (curl -I).","Cache critical lock files locally to avoid network dependencies.","Set timeouts and retry logic in CI for remote lock file downloads."],"tags":["pylock","io-error","network","file-not-found","url"],"backgroundTag":null,"analyzedSha":"f399c3718970b1b0e2478dac5296eb62679a9b86","analyzedAt":"2026-08-08T23:01:42.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}