-
Notifications
You must be signed in to change notification settings - Fork 5
Description
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:
oxylabsversion:2.0.0
Steps to Reproduce:
-
Install
oxylabsv2.0.0:uv pip install oxylabs==2.0.0
-
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}")
-
Replace
"YOUR_OXYLABS_USERNAME"and"YOUR_OXYLABS_PASSWORD"with valid Oxylabs credentials. -
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