crewAIInc/crewAI · error · ValueError

You must pass oxylabs username and password when instantiati

Error message

You must pass oxylabs username and password when instantiating the tool or specify OXYLABS_USERNAME and OXYLABS_PASSWORD environment variables

What it means

OxylabsGoogleSearchScraperTool._get_credentials_from_env raises ValueError unless both OXYLABS_USERNAME and OXYLABS_PASSWORD are non-empty in the environment, when no username/password constructor args were supplied.

Source

Thrown at lib/crewai-tools/src/crewai_tools/tools/oxylabs_google_search_scraper_tool/oxylabs_google_search_scraper_tool.py:154

                        password=password,
                        sdk_type=sdk_type,
                    )
                except subprocess.CalledProcessError as e:
                    raise ImportError("Failed to install oxylabs package") from e
            else:
                raise ImportError(
                    "`oxylabs` package not found, please run `uv add oxylabs`"
                )

        if config is None:
            config = OxylabsGoogleSearchScraperConfig()
        super().__init__(config=config, **kwargs)

    def _get_credentials_from_env(self) -> tuple[str, str]:
        username = os.environ.get("OXYLABS_USERNAME")
        password = os.environ.get("OXYLABS_PASSWORD")
        if not username or not password:
            raise ValueError(
                "You must pass oxylabs username and password when instantiating the tool "
                "or specify OXYLABS_USERNAME and OXYLABS_PASSWORD environment variables"
            )
        return username, password

    def _run(self, query: str, **kwargs: Any) -> str:
        response = self.oxylabs_api.google.scrape_search(
            query,
            **self.config.model_dump(exclude_none=True),
        )

        content = response.results[0].content

        if isinstance(content, dict):
            return json.dumps(content)

        return str(content)

View on GitHub (pinned to 754d7323be)

Solutions

  1. Provide credentials: OxylabsGoogleSearchScraperTool(username=..., password=...).
  2. Export OXYLABS_USERNAME and OXYLABS_PASSWORD (or load .env with python-dotenv) before construction.
  3. Debug with: python -c "import os; print(os.environ.get('OXYLABS_USERNAME'), os.environ.get('OXYLABS_PASSWORD'))".

Example fix

# before
tool = OxylabsGoogleSearchScraperTool()  # ValueError

# after
tool = OxylabsGoogleSearchScraperTool(username=os.environ['OXYLABS_USERNAME'], password=os.environ['OXYLABS_PASSWORD'])
Defensive patterns

Strategy: validation

Validate before calling

import os

def has_oxylabs_creds() -> bool:
    return bool(os.environ.get("OXYLABS_USERNAME")) and bool(os.environ.get("OXYLABS_PASSWORD"))

assert has_oxylabs_creds(), "set OXYLABS_USERNAME/OXYLABS_PASSWORD"

Try / catch

try:
    tool = OxylabsGoogleSearchScraperTool()
except ValueError as e:
    if "OXYLABS_USERNAME" in str(e):
        tool = OxylabsGoogleSearchScraperTool(username=u, password=p)

Prevention

When it happens

Trigger: OxylabsGoogleSearchScraperTool() (or with only one of username/password) while one or both of the env vars are unset/empty; env vars present in the deploy config but not in the actual process env.

Common situations: Unexported shell vars, missing .env loading, CI secrets not attached, Docker run without -e/--env-file.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/0ca313e7e4ffe044. Report an issue: GitHub.