Skip to content

[Reopening #1267] Fix proxy authentication ERR_INVALID_AUTH_CREDENTIALS in crawl4ai 0.6.1-0.6.3#1281

Merged
unclecode merged 1 commit intounclecode:developfrom
garyluky:fix-proxy-authentication
Feb 1, 2026
Merged

[Reopening #1267] Fix proxy authentication ERR_INVALID_AUTH_CREDENTIALS in crawl4ai 0.6.1-0.6.3#1281
unclecode merged 1 commit intounclecode:developfrom
garyluky:fix-proxy-authentication

Conversation

@garyluky
Copy link

@garyluky garyluky commented Jul 8, 2025

Continuation of PR #1267

This PR implements the proxy authentication fixes originally proposed in #1267. Due to repository state conflicts, the original PR could not be reopened, necessitating this resubmission with identical technical changes.

Issues addressed:

Current Impact: Multiple users continue experiencing these proxy authentication failures in versions 0.6.1-0.6.3, with recent reports confirming the ongoing need for these fixes in production environments.

🐛 Problem

The proxy authentication feature in crawl4ai versions 0.6.1-0.6.3 fails with ERR_INVALID_AUTH_CREDENTIALS errors for all proxy configurations, even when valid credentials are provided.

🔍 Root Cause

The core issue was inconsistent proxy credential handling across the crawl4ai codebase:

  1. Dict-to-Object Conversion: BrowserConfig.load() and CrawlerRunConfig.load() failed to convert dictionary proxy_config inputs into proper ProxyConfig objects
  2. Context Proxy Format: Context-level proxy used plain dictionaries instead of ProxySettings objects, leading to incorrect parsing
  3. JSON Serialization: to_dict() methods didn't properly handle ProxyConfig objects during JSON serialization

🛠️ Solution

The fix involved updates to two key files:

File 1: crawl4ai/async_configs.py

Fixed dict-to-ProxyConfig conversion in from_kwargs methods:

# Before
proxy_config=kwargs.get("proxy_config", None),

# After  
proxy_config=ProxyConfig.from_dict(kwargs.get("proxy_config")) if isinstance(kwargs.get("proxy_config"), dict) else kwargs.get("proxy_config", None),

Fixed JSON serialization in to_dict methods:

# Before
"proxy_config": self.proxy_config,

# After
"proxy_config": self.proxy_config.to_dict() if hasattr(self.proxy_config, 'to_dict') else self.proxy_config,

File 2: crawl4ai/browser_manager.py

Fixed context proxy to use proper ProxySettings:

# Before - plain dict
proxy_settings = {
    "server": crawlerRunConfig.proxy_config.server,
    "username": crawlerRunConfig.proxy_config.username,
    "password": crawlerRunConfig.proxy_config.password,
}

# After - ProxySettings object
from playwright.async_api import ProxySettings
proxy_settings = ProxySettings(
    server=crawlerRunConfig.proxy_config.server,
    username=crawlerRunConfig.proxy_config.username,
    password=crawlerRunConfig.proxy_config.password,
)

✅ Testing

Before Fix:

Page.goto: net::ERR_INVALID_AUTH_CREDENTIALS

After Fix:

{
  "success": true,
  "detected_ip": "185.240.64.202",
  "proxy_working": true,
  "message": "Successfully crawled via proxy"
}

Verified with real proxy credentials - the detected IP successfully changed from the server's IP to the proxy's IP.

📝 Usage

Proxy authentication now works as documented:

Python:

config = CrawlerRunConfig(
    proxy_config=ProxyConfig(
        server="proxy.example.com:8080",
        username="your_username",
        password="your_password"
    )
)

JSON API:

{
  "urls": ["https://example.com"],
  "crawler_config": {
    "proxy_config": {
      "server": "proxy.example.com:8080",
      "username": "your_username",
      "password": "your_password"
    }
  }
}

📋 Checklist

  • Bug fix (non-breaking change)
  • Tested with real proxy credentials
  • Verified IP changes when using proxy
  • No breaking changes to existing API
  • Backward compatible
  • Resolves reported GitHub issues

🎯 Impact

  • Fixes: Critical proxy authentication bug affecting all users in crawl4ai versions 0.6.1-0.6.3
  • Compatibility: Fully backward compatible
  • Testing: Production tested with real proxy providers

Note

This is a continuation of the work from PR #1267. The fix addresses the core authentication issues that users are actively experiencing.

Summary by CodeRabbit

  • Refactor
    • Improved consistency in handling proxy settings, ensuring proxy configurations are properly converted and serialized across configuration options.
    • Updated internal logic for assigning proxy settings to use a standardized object, enhancing reliability when launching browsers with proxies.

- Fix dict-to-ProxyConfig conversion in BrowserConfig and CrawlerRunConfig
- Fix JSON serialization of ProxyConfig objects in to_dict methods
- Fix context proxy to use ProxySettings instead of plain dict
- Resolves proxy authentication issues
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 8, 2025

Walkthrough

The changes update the handling of proxy configuration across configuration classes and browser context creation. Configuration classes now consistently convert proxy configuration dictionaries to ProxyConfig instances and serialize them using to_dict() when needed. The browser manager now uses Playwright's ProxySettings object directly instead of manually constructing proxy dictionaries.

Changes

File(s) Change Summary
crawl4ai/async_configs.py Updated BrowserConfig and CrawlerRunConfig to convert proxy_config dicts to ProxyConfig instances on load and serialize them with to_dict() on export. Modified from_kwargs and to_dict methods accordingly.
crawl4ai/browser_manager.py Refactored proxy assignment in create_browser_context to use Playwright's ProxySettings object instead of a manual dictionary.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ConfigClass
    participant ProxyConfig

    User->>ConfigClass: from_kwargs(kwargs)
    alt proxy_config is dict
        ConfigClass->>ProxyConfig: from_dict(proxy_config)
        ProxyConfig-->>ConfigClass: ProxyConfig instance
        ConfigClass-->>User: ConfigClass instance with ProxyConfig
    else proxy_config is not dict
        ConfigClass-->>User: ConfigClass instance with original proxy_config
    end

    User->>ConfigClass: to_dict()
    alt proxy_config has to_dict()
        ConfigClass->>ProxyConfig: to_dict()
        ProxyConfig-->>ConfigClass: dict
        ConfigClass-->>User: dict with serialized proxy_config
    else
        ConfigClass-->>User: dict with raw proxy_config
    end
Loading
sequenceDiagram
    participant BrowserManager
    participant Playwright.ProxySettings

    BrowserManager->>BrowserManager: create_browser_context()
    alt proxy_config present
        BrowserManager->>Playwright.ProxySettings: new(server, username, password)
        Playwright.ProxySettings-->>BrowserManager: ProxySettings object
        BrowserManager->>BrowserManager: set context_settings["proxy"] = ProxySettings
    end
    BrowserManager-->>BrowserManager: create context with settings
Loading

Poem

In configs and browsers, a proxy anew,
Now objects, not dicts, see their debut.
With to_dict they serialize,
In Playwright form they harmonize.
Hopping through code, neat and precise—
Proxy handling now feels quite nice!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
crawl4ai/async_configs.py (1)

211-319: Consolidate ProxyConfig definitions to eliminate duplication

The ProxyConfig class is defined in both crawl4ai/async_configs.py and crawl4ai/proxy_strategy.py, which risks divergence and makes maintenance harder. Please centralize the implementation in one module (for example, async_configs.py) and have all other code import it from there.

• Remove the class ProxyConfig block from crawl4ai/proxy_strategy.py
• Add from .async_configs import ProxyConfig at the top of crawl4ai/proxy_strategy.py
• Update crawl4ai/__init__.py, docs/examples/*, deploy/docker/c4ai-code-context.md, etc., to import ProxyConfig only from its canonical location
• Run a full pass on tests and examples to confirm nothing breaks after consolidation

🧹 Nitpick comments (1)
crawl4ai/async_configs.py (1)

513-513: Fix inconsistent default value handling.

The static analysis hint is correct - kwargs.get("proxy_config", None) should be kwargs.get("proxy_config") since get() returns None by default when the key doesn't exist.

-            proxy_config=ProxyConfig.from_dict(kwargs.get("proxy_config")) if isinstance(kwargs.get("proxy_config"), dict) else kwargs.get("proxy_config", None),
+            proxy_config=ProxyConfig.from_dict(kwargs.get("proxy_config")) if isinstance(kwargs.get("proxy_config"), dict) else kwargs.get("proxy_config"),
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 02f3127 and 1d6efb6.

📒 Files selected for processing (2)
  • crawl4ai/async_configs.py (4 hunks)
  • crawl4ai/browser_manager.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
crawl4ai/async_configs.py (1)
crawl4ai/proxy_strategy.py (3)
  • ProxyConfig (10-118)
  • from_dict (68-75)
  • to_dict (98-105)
🪛 Ruff (0.11.9)
crawl4ai/async_configs.py

513-513: Use kwargs.get("proxy_config") instead of kwargs.get("proxy_config", None)

Replace kwargs.get("proxy_config", None) with kwargs.get("proxy_config")

(SIM910)

🔇 Additional comments (4)
crawl4ai/async_configs.py (3)

549-549: Proper proxy configuration serialization implemented.

The implementation correctly handles both ProxyConfig objects and raw dictionaries by checking for the to_dict method before calling it.


1124-1124: Good implementation of proxy config conversion.

The logic correctly converts dictionary proxy configurations to ProxyConfig objects while preserving existing ProxyConfig instances. This ensures consistent handling across the codebase.


1237-1237: Consistent serialization pattern maintained.

The serialization logic matches the pattern used in BrowserConfig.to_dict(), ensuring consistent behavior across configuration classes.

crawl4ai/browser_manager.py (1)

861-866: Excellent improvement using Playwright's ProxySettings.

The change from manually constructing proxy dictionaries to using Playwright's ProxySettings object improves type safety and ensures proper validation of proxy credentials. This directly addresses the proxy authentication issues mentioned in the PR objectives.

@zzy-life
Copy link

zzy-life commented Aug 7, 2025

image

It doesn't seem to work, or report an error

@unclecode unclecode changed the base branch from main to develop February 1, 2026 07:04
@unclecode unclecode merged commit 980dc73 into unclecode:develop Feb 1, 2026
1 check passed
@unclecode
Copy link
Owner

Merged into develop — thanks for fixing the proxy auth issue. We resolved a minor merge conflict in to_dict serialization. Will be in the next release, and we'll add you to CONTRIBUTORS.md.

unclecode added a commit that referenced this pull request Feb 1, 2026
- PR #1077: Fix bs4 deprecation warning (text -> string)
- PR #1281: Fix proxy auth ERR_INVALID_AUTH_CREDENTIALS
- Comment on PR #1081 guiding author on needed DFS/BFF fixes
- Update CONTRIBUTORS.md and PR-TODOLIST.md
@ntohidi ntohidi mentioned this pull request Mar 16, 2026
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Failing to auth with proxy [Bug]: Proxy not working

3 participants