Skip to content

amount_from_string requires _args in oxylabs v2.0.0 despite documentation/examples #29

@ryullulala

Description

@ryullulala

Description:

When using amount_from_string in parsing_instructions with oxylabs version 2.0.0, the library's internal validation (oxylabs/utils/utils.py) unexpectedly requires a non-empty string for _args. This contradicts the official documentation examples (e.g., [insert link to relevant documentation if available, or describe where you saw the example]), which show amount_from_string being used without an _args parameter.

Problem:

The validate_fn_args function, specifically when calling validate_string for fn_name.AMOUNT_FROM_STRING, enforces that _args must be a non-empty string. If _args is not provided (as per the documentation examples), a ValueError: _args must be a non-empty string is raised.

Affected Library Version:

  • oxylabs version: 2.0.0

Steps to Reproduce:

  1. Install oxylabs v2.0.0:

    uv pip install oxylabs==2.0.0
  2. Create a Python script (e.g., test_oxylabs.py) with the following content:

    from oxylabs import RealtimeClient
    
    username = "YOUR_OXYLABS_USERNAME"
    password = "YOUR_OXYLABS_PASSWORD"
    
    parsing_instructions_with_error = {
        "total_count": {
            "_fns": [
                {
                    "_fn": "xpath_one",
                    "_args": [".//span[contains(@class, 'total-results')]/text()"]
                },
                {
                    "_fn": "amount_from_string"  # This line causes the error
                }
            ]
        }
    }
    parsing_instructions_no_error = {
        "total_count": {
            "_fns": [
                {
                    "_fn": "xpath_one",
                    "_args": [".//span[contains(@class, 'total-results')]/text()"]
                },
                {
                    "_fn": "amount_from_string", "_args": "dummy" 
                }
            ]
        }
    }
    
    client = RealtimeClient(username, password)
    try:
        result = client.universal.scrape_url(
            "https://google.com",
            parse=True,
            parsing_instructions=parsing_instructions_with_error,
            render="html",
        )
        print(result)
    except ValueError as e:
        print(f"An error occurred: {e}")
  3. Replace "YOUR_OXYLABS_USERNAME" and "YOUR_OXYLABS_PASSWORD" with valid Oxylabs credentials.

  4. Run the script:

    python test_oxylabs.py

Expected Behavior:

The script should execute without a ValueError and the amount_from_string function should process the extracted text as per its intended functionality, consistent with how it's presented in the documentation examples without an explicit _args requirement.

Actual Behavior:

A ValueError: _args must be a non-empty string is raised due to the internal validation for amount_from_string.

Suggested Resolution (Optional):

Either update the oxylabs library to remove the _args requirement for amount_from_string (if it's not functionally needed), or update the documentation to clearly state that _args is a mandatory parameter for this function in parsing_instructions.

Reference

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