Skip to content

basic example doesn't work #105

Closed
Closed
@madhur-tandon

Description

@madhur-tandon

basic example doesn't work:

import os
import asyncio
from stagehand import Stagehand, StagehandConfig

async def main():
    # Configure Stagehand
    config = StagehandConfig(
        env="LOCAL",
        model_name="google/gemini-2.0-flash",
        model_client_options={"apiKey": "xxxxx"},
    )

    # Initialize Stagehand
    stagehand = Stagehand(config=config)
    await stagehand.init()
    print(f"Session created: {stagehand.session_id}")
    
    # Get page reference
    page = stagehand.page

    # Navigate to a page
    await page.goto("https://google.com/")

if __name__ == "__main__":
    asyncio.run(main())

and leads to the following:

2025-06-19 01:34:34 INFO - Launching new local browser context...
2025-06-19 01:34:35 INFO - Local browser context launched successfully.
Session created: None
2025-06-19 01:34:35 ERROR - [EXCEPTION] Header value must be str or bytes, not <class 'NoneType'>
Traceback (most recent call last):
  File "/Users/madhur/Desktop/stagehand/tranzit-py/vietnam.py", line 68, in <module>
    asyncio.run(main())
  File "/Users/madhur/miniforge3/envs/tranzit/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Users/madhur/miniforge3/envs/tranzit/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/Users/madhur/Desktop/stagehand/tranzit-py/vietnam.py", line 47, in main
    await page.goto("https://google.com/")
  File "/Users/madhur/miniforge3/envs/tranzit/lib/python3.10/site-packages/stagehand/page.py", line 103, in goto
    result = await self._stagehand._execute("navigate", payload)
  File "/Users/madhur/miniforge3/envs/tranzit/lib/python3.10/site-packages/stagehand/api.py", line 111, in _execute
    async with self._client.stream(
  File "/Users/madhur/miniforge3/envs/tranzit/lib/python3.10/contextlib.py", line 199, in __aenter__
    return await anext(self.gen)
  File "/Users/madhur/miniforge3/envs/tranzit/lib/python3.10/site-packages/httpx/_client.py", line 1570, in stream
    request = self.build_request(
  File "/Users/madhur/miniforge3/envs/tranzit/lib/python3.10/site-packages/httpx/_client.py", line 367, in build_request
    headers = self._merge_headers(headers)
  File "/Users/madhur/miniforge3/envs/tranzit/lib/python3.10/site-packages/httpx/_client.py", line 430, in _merge_headers
    merged_headers.update(headers)
  File "/Users/madhur/miniforge3/envs/tranzit/lib/python3.10/site-packages/httpx/_models.py", line 275, in update
    headers = Headers(headers)
  File "/Users/madhur/miniforge3/envs/tranzit/lib/python3.10/site-packages/httpx/_models.py", line 156, in __init__
    bytes_value = _normalize_header_value(v, encoding)
  File "/Users/madhur/miniforge3/envs/tranzit/lib/python3.10/site-packages/httpx/_models.py", line 81, in _normalize_header_value
    raise TypeError(f"Header value must be str or bytes, not {type(value)}")
TypeError: Header value must be str or bytes, not <class 'NoneType'>

My editor also gives the following warning and these arguments seem like they follow JS based naming..

Arguments missing for parameters "apiKey", "projectId", "apiUrl", "modelApiKey", "verbose", "logger", "use_rich_logging", "domSettleTimeoutMs", "browserbaseSessionCreateParams", "enableCaching", "browserbaseSessionID", "modelName", "selfHeal", "waitForCaptchaSolves", "systemPrompt", "localBrowserLaunchOptions", "use_api", "experimental"Pylance[reportCallIssue](https://github.com/microsoft/pylance-release/blob/main/docs/diagnostics/reportCallIssue.md)
No parameter named "model_client_options"Pylance[reportCallIssue](https://github.com/microsoft/pylance-release/blob/main/docs/diagnostics/reportCallIssue.md)

I only did pip install stagehand and then playwright install in a fresh new conda environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions