Skip to content

[Bug?] Proxy parameter always rejected with "Proxy must have scheme, host, and port" on hCaptcha token endpoint #35

@yairbenshi

Description

@yairbenshi

Description:

Passing a proxy object to the hCaptcha token endpoint always returns error 10, regardless of field names or endpoint used. Removing the proxy field entirely allows jobs to be accepted and solved normally.

Error response:

{"error": 10, "message": "Invalid request", "type": "Proxy must have scheme, host, and port"}
Combinations tested (all return error 10):

scheme, host, port, username, password on /v1/token/hcaptcha with Bearer auth
scheme, host, port, username, password on /v1/token/hcaptcha with Basic auth
scheme, host, port, username, password on /token/ with Bearer auth
type, host, port, login, password (matching SDK Proxy TypedDict) on /token/ with Bearer auth

Reproduce — direct HTTP

import asyncio, aiohttp
async def main():
    body = {
        "sitekey": "<sitekey>",
        "url": "https://example.com",
        "proxy": {
            "scheme": "http",
            "host": "brd.superproxy.io",
            "port": 33335,
            "username": "my-proxy-user",
            "password": "my-proxy-pass",
        },
        "data": {"rqdata": "test123"},
    }
    headers = {"Authorization": "Bearer <API_KEY>"}
    async with aiohttp.ClientSession() as session:
        async with session.post(
            "https://api.nopecha.com/v1/token/hcaptcha",
            json=body,
            headers=headers,
        ) as resp:
            print(resp.status, await resp.json())
            # 400 {'error': 10, 'message': 'Invalid request', 'type': 'Proxy must have scheme, host, and port'}
asyncio.run(main())

Reproduce — official SDK (v2.0.1)

import asyncio, aiohttp
from nopecha.api.aiohttp import AsyncHTTPXAPIClient
async def main():
    proxy = {
        "type": "http",
        "host": "brd.superproxy.io",
        "port": 33335,
        "login": "my-proxy-user",
        "password": "my-proxy-pass",
    }
    # base_url required because async client sends relative URLs
    async with aiohttp.ClientSession(base_url="https://api.nopecha.com") as session:
        client = AsyncHTTPXAPIClient("<API_KEY>", client=session)
        result = await client.solve_hcaptcha(
            "<sitekey>",
            "https://example.com",
            enterprise=True,
            proxy=proxy,
            rqdata="test123",
        )
        print(result)
asyncio.run(main())

Additional notes -
The SDK Proxy TypedDict uses type and login, but the API reference documents scheme and username. Neither set of names works.
The async SDK client (AsyncAPIClient) sends requests to relative paths like /token/ without prepending self.host, unlike the sync APIClient which uses f"{self.host}/token/". This requires the caller to set base_url on the aiohttp session as a workaround.

Environment -
nopecha SDK version: 2.0.1
Python: 3.10
aiohttp: 3.9+

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions