{"record":{"id":"0351f959c0b942a1","repo":"SeleniumHQ/selenium","slug":"cannot-read-storage-state-file-file-path-e","errorCode":null,"errorMessage":"Cannot read storage state file {file_path}: {e}","messagePattern":"Cannot read storage state file (.+?): (.+?)","errorType":"exception","errorClass":"OSError","httpStatus":null,"severity":"error","filePath":"py/selenium/webdriver/common/api_request_context.py","lineNumber":573,"sourceCode":"            storage_state: Optional cookies to pre-load, as a dict, JSON file path, or Path.\n            fail_on_status_code: If True, raise APIRequestFailure for non-2xx responses.\n\n        Returns:\n            An _IsolatedAPIRequestContext instance.\n        \"\"\"\n        cookies: list[dict] = []\n        if storage_state is not None:\n            if isinstance(storage_state, (str, pathlib.Path)):\n                file_path = pathlib.Path(storage_state)\n                if not file_path.exists():\n                    raise FileNotFoundError(f\"Storage state file not found: {file_path}\")\n                try:\n                    with open(file_path) as f:\n                        state = json.load(f)\n                except json.JSONDecodeError as e:\n                    raise ValueError(f\"Invalid JSON in storage state file {file_path}: {e}\") from e\n                except OSError as e:\n                    raise OSError(f\"Cannot read storage state file {file_path}: {e}\") from e\n            else:\n                state = storage_state\n            cookies = list(state.get(\"cookies\", []))\n\n        return _IsolatedAPIRequestContext(\n            base_url=base_url,\n            extra_headers=extra_headers,\n            cookies=cookies,\n            timeout=self._timeout,\n            max_redirects=self._max_redirects,\n            fail_on_status_code=fail_on_status_code,\n        )\n\n    def get_storage_state(self, path: str | pathlib.Path | None = None) -> dict[str, Any]:\n        \"\"\"Export the current browser cookies as a storage state dict.\n\n        Args:\n            path: Optional file path to save the storage state as JSON.","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/py/selenium/webdriver/common/api_request_context.py#L555-L591","documentation":"While reading the storage-state file, if an `OSError` occurs that is not a JSON decode error (e.g. permission denied, broken symlink, disk read error), Selenium re-raises it as `OSError` with the path and the underlying error. This distinguishes OS-level read problems from JSON syntax problems.","triggerScenarios":"File exists and is valid JSON but is unreadable due to permissions (`PermissionError`), a broken symlink, a lock, or a transient I/O error. The file is a directory (though `is_file` would normally catch that earlier).","commonSituations":"File owned by another user / wrong mode in shared CI. NFS/network filesystem read hiccups. Antivirus locking the file. Container volume permission mismatch.","solutions":["Check permissions: `os.access(p, os.R_OK)` and chmod/chown as needed.","Ensure the file is a regular file: `pathlib.Path(p).is_file()`.","Run the process as a user with read access to the file.","Move the file to a location the process owns."],"exampleFix":"// before\nctx = api.new_context(storage_state=\"/root/state.json\")  # OSError: permission\n// after\n# copy to a readable location first\nimport shutil; shutil.copy(\"/root/state.json\", \"./state.json\")\nctx = api.new_context(storage_state=\"./state.json\")","handlingStrategy":"validation","validationCode":"import os\np = \"state.json\"\nassert os.access(p, os.R_OK), f\"storage state file not readable: {p}\"\nctx = api.new_context(storage_state=p)","typeGuard":"import os\ndef storage_state_file_readable(path) -> bool:\n    return os.access(path, os.R_OK)","tryCatchPattern":"try:\n    ctx = api.new_context(storage_state=path)\nexcept OSError as e:\n    # permission/IO issue; copy to a readable location or pass a dict\n    ctx = api.new_context(storage_state=json.load(open(local_copy)))","preventionTips":["Check os.access(path, os.R_OK) before loading.","Ensure the process owns or can read the file.","Keep storage-state files under the project, not shared roots."],"tags":["storage-state","filesystem","permissions","api-request"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}