Skip to content

Client creates zones in __aenter__ even when no zone is used; accounts without a payment method fail with 403 before any scraper call #57

Description

@anil-bd

SDK: brightdata-sdk 2.5.2 (latest on PyPI), Python 3.12, macOS. Account without a payment method (a new free account).

Steps to reproduce

pip install brightdata-sdk==2.5.2
export BRIGHTDATA_API_TOKEN=YOUR_API_KEY   # a token from an account with no payment method
python - <<'PY'
from brightdata import SyncBrightDataClient

with SyncBrightDataClient() as client:   # every argument at its default
    print(client.search.instagram.profiles("nasa").data[0]["followers"])
PY

Actual

The client never gets to the scraper call. Entering the context manager fails:

Failed to create zone 'sdk_unlocker' due to insufficient permissions

❌ ZONE CREATION BLOCKED: API token lacks required permissions
   Error: Forbidden (403): {"msg":"A payment method is required for this zone action. Please add a payment method and try again.","err_id":"payment_method_required"}
   Fix: Update your token permissions at https://brightdata.com/cp/setting/users
AuthenticationError: Forbidden (403): {"msg":"A payment method is required for this zone action. Please add a payment method and try again.","err_id":"payment_method_required"}
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x10516cc50>

Expected

A scraper call needs no zone. The client should not try to create sdk_unlocker and sdk_serp unless Web Unlocker or SERP is actually used. The _ensure_zones docstring already describes that behaviour: "This is called automatically before the first API request." In practice it is called unconditionally from __aenter__ (brightdata/client.py, await self._ensure_zones() right after the optional token validation), so every free account fails on the first with block, before any request.

Three smaller things in the same path:

  1. The printed advice, "API token lacks required permissions ... Update your token permissions", is wrong for this error. The API says a payment method is missing, not a permission.
  2. When __aenter__ raises, engine.__aexit__ is not called, hence the "Unclosed client session" warning.
  3. auto_create_zones defaults to True. Defaulting to False, or creating lazily on first Web Unlocker / SERP use, would remove the failure for everyone who only uses scrapers.

Workaround

SyncBrightDataClient(auto_create_zones=False). Every example in https://github.com/brightdata/instagram-scraper-python passes it for this reason.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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