{"id":1479,"library":"fake-useragent","title":"fake-useragent","description":"fake-useragent is a Python library that generates up-to-date and realistic browser user-agent strings for web scraping and testing purposes. It dynamically fetches a database of real-world user agents to provide diverse and current options. The current version is 2.2.0, with minor releases occurring every few months to update the user-agent database or fix small issues.","status":"active","version":"2.2.0","language":"en","source_language":"en","source_url":"https://github.com/fake-useragent/fake-useragent","tags":["user-agent","web scraping","faker","http","browser"],"install":[{"cmd":"pip install fake-useragent","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"UserAgent","correct":"from fake_useragent import UserAgent"},{"note":"Exception for handling errors like network issues during data fetching.","symbol":"FakeUserAgentError","correct":"from fake_useragent import FakeUserAgentError"}],"quickstart":{"code":"from fake_useragent import UserAgent, FakeUserAgentError\n\ntry:\n    ua = UserAgent()\n    print(f\"Random User-Agent: {ua.random}\")\n    print(f\"Chrome User-Agent: {ua.chrome}\")\n    print(f\"Firefox User-Agent: {ua.firefox}\")\n    print(f\"User-Agent for macOS: {ua.get_ua('chrome', os='macos')}\")\n    print(f\"User-Agent for desktop: {ua.get_ua(platform='desktop')}\")\nexcept FakeUserAgentError as e:\n    print(f\"Error fetching user agents: {e}\")\n    print(\"This might be due to network issues or the first-time data download failing.\")","lang":"python","description":"This quickstart demonstrates how to initialize `UserAgent` and retrieve various types of user-agent strings. It includes basic error handling for potential network issues during the initial data download or cache refresh."},"warnings":[{"fix":"Ensure all OS and browser option parameters (e.g., in `ua.get_ua(browser='Chrome', os='Windows')`) are passed with the correct casing as specified in the documentation (e.g., 'chrome', 'firefox', 'windows', 'macos').","message":"Since version 2.0.0, OS and browser options are case-sensitive. Previously, they might have been implicitly converted or handled with more flexibility.","severity":"breaking","affected_versions":"2.0.0+"},{"fix":"Replace `platform='pc'` with `platform='desktop'` when calling methods like `ua.get_ua()` to specify desktop user agents.","message":"In version 2.0.0, the `platform` type value 'pc' was changed to 'desktop'. If you were specifically requesting desktop user agents using `platform='pc'`, your code will no longer work as expected.","severity":"breaking","affected_versions":"2.0.0+"},{"fix":"Remove `min_percentage` from your calls, as it will not filter user agents based on usage. Rely on other parameters for selection.","message":"Since version 1.5.0, the `min_percentage` parameter for filtering user agents is effectively useless. The new data sources introduced in this version and later do not provide usage statistics, so this filter is ignored.","severity":"gotcha","affected_versions":"1.5.0+"},{"fix":"Upgrade your Python environment to version 3.9 or newer if you are using fake-useragent 2.0.1 or later.","message":"fake-useragent requires Python 3.9 or newer since version 2.0.1. Attempting to use it with older Python versions will result in compatibility errors.","severity":"gotcha","affected_versions":"2.0.1+"},{"fix":"Ensure reliable network access for initialization. Handle `FakeUserAgentError` for network-related failures. For restricted environments, consider pre-caching the data or using options like `cache=False` (though this fetches data on every call) or `use_cache_server=False`.","message":"On its first run (or when the cache expires), `fake-useragent` attempts to download a JSON file (~500KB) from an external source (currently intoli.com). This can introduce network delays, fail due to connectivity issues, or be blocked by firewalls/proxies.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}