{"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/d7d0d0a39494e28ec1c407bd0680e4a4d1067791/src/pip/_internal/utils/pylock.py#L263-L299","documentation":"InstallationError wrapping any non-diagnostic exception raised while fetching/reading the pylock file content in _get_pylock_path_or_url_content (or, by chaining, an earlier read failure). DiagnosticPipError subclasses are re-raised unchanged; everything else (network, filesystem, decode) is wrapped with the lock path for context.","triggerScenarios":"select_from_pylock_path_or_url calls _get_pylock_path_or_url_content; it raises a non-DiagnosticPipError (HTTP error from session.get, connection refused, DNS failure, file not found, permission denied, unicode decode error on a local file). The except Exception catches and re-raises as InstallationError 'Error reading pylock file ...: <exc>'.","commonSituations":"Typo in the pylock URL; the host is down or returns 404/500; the local pylock path doesn't exist or isn't readable; the file isn't UTF-8; corporate proxy/firewall blocking the fetch; expired/misconfigured credentials for a private index hosting the lock.","solutions":["Verify the pylock path/URL resolves (curl/wget the URL, or ls the local path).","For HTTP errors, check status with `curl -i <url>` and fix auth/proxy/cert as needed.","For local files, confirm the path and read permissions; convert the file to UTF-8 if decoding failed.","If it's a transient network issue, retry; ensure PIP_INDEX_URL/PIP_CERT/PIP_CLIENT_CERT are set for private hosts."],"exampleFix":"# before\npip install -r https://example.com/typo-lock.toml   # 404 → Error reading pylock file\n\n# after - correct URL, verify first\ncurl -i https://example.com/lock.toml\npip install -r https://example.com/lock.toml","handlingStrategy":"try-catch","validationCode":"def pylock_url_is_fetchable(url, session):\n    try:\n        resp = session.get(url, stream=True)\n        resp.raise_for_status()\n        return True\n    except Exception as e:\n        return False\n# probe before invoking pip -r <remote lock>","typeGuard":null,"tryCatchPattern":"try:\n    pip_install('-r', lock_path_or_url)\nexcept InstallationError as e:\n    msg = str(e)\n    if 'Error reading pylock file' in msg:\n        if is_transient_network(msg):    # 5xx / connection / DNS\n            backoff_and_retry(lambda: pip_install('-r', lock_path_or_url))\n        else:\n            fix_lock_source(lock_path_or_url)  # 404 / perms / encoding\n            pip_install('-r', lock_path_or_url)\n    else:\n        raise","preventionTips":["curl/verify the lock URL/path before pip uses it.","Ensure UTF-8 encoding for locally-served pylock files.","Configure PIP_CERT/PIP_CLIENT_CERT/proxy for private hosts hosting the lock."],"tags":["pip","pylock","network","io","lockfile","url"],"analyzedSha":"d7d0d0a39494e28ec1c407bd0680e4a4d1067791","analyzedAt":"2026-08-04T20:55:04.259Z","schemaVersion":2}