{"id":7860,"library":"webdav4","title":"WebDAV4 Client Library","description":"webdav4 is a modern Python library for interacting with WebDAV servers, providing both a low-level client (`WebdavClient`) and an `fsspec`-compatible filesystem (`WebdavFS`). It is currently at version 0.11.0 and is actively maintained, with regular releases addressing features and bug fixes. It aims to offer a robust and user-friendly way to manage files on WebDAV resources.","status":"active","version":"0.11.0","language":"en","source_language":"en","source_url":"https://github.com/webdav-py/webdav4","tags":["webdav","fsspec","client","filesystem","http","dav"],"install":[{"cmd":"pip install webdav4","lang":"bash","label":"Install webdav4"}],"dependencies":[],"imports":[{"note":"The library was renamed from `webdav` to `webdav4` in version 0.10.0. The old package name is no longer maintained and will result in `ModuleNotFoundError`.","wrong":"from webdav.client import WebdavClient","symbol":"WebdavClient","correct":"from webdav4.client import WebdavClient"},{"note":"The library was renamed from `webdav` to `webdav4` in version 0.10.0. The old package name is no longer maintained and will result in `ModuleNotFoundError`.","wrong":"from webdav.fs import WebdavFS","symbol":"WebdavFS","correct":"from webdav4.fs import WebdavFS"}],"quickstart":{"code":"import os\nfrom webdav4.fs import WebdavFS\n\n# Replace with your WebDAV server details or set as environment variables\nWEBDAV_URL = os.environ.get('WEBDAV_URL', 'http://localhost:8000/webdav/')\nWEBDAV_USER = os.environ.get('WEBDAV_USER', 'user')\nWEBDAV_PASS = os.environ.get('WEBDAV_PASS', 'password')\n\nif not all([WEBDAV_URL, WEBDAV_USER, WEBDAV_PASS]):\n    print(\"Please set WEBDAV_URL, WEBDAV_USER, WEBDAV_PASS environment variables or update the script.\")\n    exit(1)\n\ntry:\n    # Initialize WebdavFS\n    # For self-signed certificates or HTTP, you might need to add verify=False\n    fs = WebdavFS(\n        url=WEBDAV_URL,\n        username=WEBDAV_USER,\n        password=WEBDAV_PASS,\n        # verify=False # Uncomment if you have SSL certificate issues\n    )\n\n    print(f\"Connecting to WebDAV server: {WEBDAV_URL}\")\n\n    # List contents of the root directory\n    print(f\"Listing contents of '/':\")\n    for item in fs.ls('/', detail=True):\n        print(f\"  - {item['name']} (Type: {item['type']}, Size: {item.get('size', 'N/A')})\")\n\n    # Example: Create a directory\n    test_dir_name = 'my_test_dir_webdav4'\n    if not fs.exists(test_dir_name):\n        fs.mkdir(test_dir_name)\n        print(f\"Successfully created directory: {test_dir_name}\")\n    else:\n        print(f\"Directory '{test_dir_name}' already exists.\")\n\n    # Example: Write and read a file\n    test_file_path = f'{test_dir_name}/hello.txt'\n    file_content = 'Hello, WebDAV4!'\n\n    with fs.open(test_file_path, 'wb') as f:\n        f.write(file_content.encode('utf-8'))\n    print(f\"Wrote content to {test_file_path}\")\n\n    with fs.open(test_file_path, 'rb') as f:\n        read_content = f.read().decode('utf-8')\n    print(f\"Read content from {test_file_path}: '{read_content}'\")\n\n    # Clean up (optional)\n    # fs.rm(test_file_path)\n    # print(f\"Removed file: {test_file_path}\")\n    # fs.rmdir(test_dir_name)\n    # print(f\"Removed directory: {test_dir_name}\")\n\nexcept Exception as e:\n    print(f\"\\nAn error occurred: {e}\")\n    print(\"Please ensure the WebDAV server is running and accessible, \")\n    print(\"and that WEBDAV_URL, WEBDAV_USER, WEBDAV_PASS environment variables are set correctly.\")\n    print(\"If you are facing SSL issues, try adding `verify=False` to the WebdavFS constructor.\")","lang":"python","description":"This quickstart demonstrates how to initialize `WebdavFS`, list directory contents, create a new directory, and write/read a file. Remember to replace placeholder credentials with your actual WebDAV server details or set them as environment variables. SSL verification might need to be disabled for servers with self-signed certificates."},"warnings":[{"fix":"Uninstall the old package (`pip uninstall webdav` if installed), install the new one (`pip install webdav4`), and update all import statements to use `webdav4` (e.g., `from webdav4.client import WebdavClient`).","message":"The package name was changed from `webdav` to `webdav4` starting with version 0.10.0. Projects using `import webdav` will fail with a `ModuleNotFoundError`.","severity":"breaking","affected_versions":"0.10.0+"},{"fix":"Review the latest documentation for `WebdavClient` and `WebdavFS` constructor arguments. For `WebdavFS`, pass the full URL to `url` and credentials directly as `username` and `password`. For `WebdavClient`, use `base_url` and `username`/`password`.","message":"The constructor signatures for `WebdavClient` and `WebdavFS` underwent significant changes in version 0.10.0. Specifically, `WebdavClient` now uses `base_url` instead of `url`, and the handling of authentication arguments has been refactored.","severity":"breaking","affected_versions":">=0.10.0"},{"fix":"To bypass certificate verification (use with caution and only for development/testing), pass `verify=False` to the `WebdavClient` or `WebdavFS` constructor, e.g., `WebdavFS(url=..., username=..., password=..., verify=False)`.","message":"Connecting to WebDAV servers with self-signed SSL certificates or untrusted Certificate Authorities (CAs) will cause `ssl.SSLCertVerificationError` by default due to strict certificate validation.","severity":"gotcha","affected_versions":"All"},{"fix":"For direct `WebdavFS` instantiation, use `WebdavFS(url='https://example.com/webdav/')`. For `fsspec.filesystem` or `fsspec.open`, use `fsspec.filesystem('webdav', url='webdavs://example.com/webdav/')` or `fsspec.open('webdavs://example.com/webdav/path/to/file', ...)`. Note that `fsspec.filesystem` often expects an `url` argument, but it's used for the *fsspec* URL, not the base_url.","message":"When using `fsspec` directly to create a filesystem, ensure you use the `webdav` or `webdavs` protocol handler. The `url` parameter for direct `WebdavFS` instantiation expects `http://` or `https://` URLs, but `fsspec.open` expects `webdav://` or `webdavs://`.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install webdav4` and change all `import webdav` statements to `import webdav4` (or specific submodules like `from webdav4.client import WebdavClient`).","cause":"Attempting to import the old package name, `webdav`, which was renamed to `webdav4` in version 0.10.0.","error":"ModuleNotFoundError: No module named 'webdav'"},{"fix":"Double-check the `username` and `password` values passed to `WebdavFS` or `WebdavClient`. Ensure the URL is correct and includes the proper path to the WebDAV resource. Some complex setups might require specific `auth` parameters for `WebdavClient`.","cause":"Incorrect or missing authentication credentials (username/password), or the WebDAV server requires a different authentication method not correctly provided.","error":"webdav4.exceptions.WebdavError: 401 Unauthorized"},{"fix":"If connecting to a server with a self-signed or untrusted certificate for development/testing, add `verify=False` to the `WebdavClient` or `WebdavFS` constructor, e.g., `WebdavFS(url=..., username=..., password=..., verify=False)`.","cause":"The WebDAV server is using an SSL certificate that cannot be verified by your system's trusted CAs, typically a self-signed certificate.","error":"ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate"},{"fix":"Verify the exact path and case sensitivity of the file/directory on the WebDAV server. Use methods like `fs.ls('/')` to inspect available paths and ensure the target exists before attempting operations like `open`, `cat`, or `rm`.","cause":"The specified file or directory path does not exist on the WebDAV server, or there's a case-sensitivity mismatch.","error":"FileNotFoundError: /path/to/nonexistent/file (or directory)"}]}