Hi, thanks for maintaining ai-cloudscraper.
I found a reproducible RuntimeError when using ai-cloudscraper 3.8.4 with POST requests that pass payload via json=....
Observed error:
RuntimeError: dictionary changed size during iteration
Traceback consistently points to:
cloudscraper/anti_detection.py
pre_request_processing -> payload_obfuscator.obfuscate_payload -> _obfuscate_dict -> _encode_values
with the failing line similar to:
for key, value in data.items()
Important observations:
- The issue reproduces under multiple modes:
- hybrid + turbo
- hybrid (without turbo)
- compatibility_mode=True
- It is not tied to one specific business payload. It appears in both:
- /web/message
- /marketplace/explore/items
- Request snapshots show that the outgoing payload dict is structurally stable before request dispatch.
- The problem seems to happen inside the library while processing kwargs['json'] during payload obfuscation.
Workaround on application side:
Converting all json=payload calls to:
data=json.dumps(payload)
- plus
Content-Type: application/json
appears to avoid the failing obfuscation path.
Suspected root cause:
The library may be iterating over a dict while mutating it internally during payload obfuscation.
Suggested fix:
Please review the payload obfuscation path for kwargs['json'], especially any code that iterates over dict items while mutating the same dict.
A safer approach may be:
- iterate over
list(data.items())
- or deep-copy the dict before mutation
Thanks.
Hi, thanks for maintaining ai-cloudscraper.
I found a reproducible RuntimeError when using ai-cloudscraper 3.8.4 with POST requests that pass payload via
json=....Observed error:
RuntimeError: dictionary changed size during iteration
Traceback consistently points to:
cloudscraper/anti_detection.py
pre_request_processing -> payload_obfuscator.obfuscate_payload -> _obfuscate_dict -> _encode_values
with the failing line similar to:
for key, value in data.items()
Important observations:
Workaround on application side:
Converting all
json=payloadcalls to:data=json.dumps(payload)Content-Type: application/jsonappears to avoid the failing obfuscation path.
Suspected root cause:
The library may be iterating over a dict while mutating it internally during payload obfuscation.
Suggested fix:
Please review the payload obfuscation path for
kwargs['json'], especially any code that iterates over dict items while mutating the same dict.A safer approach may be:
list(data.items())Thanks.