Change8
Error1 reports

Fix UnboundLocalError

in Requests

Solution

The UnboundLocalError arises when a variable is referenced before it's assigned within its scope, often inside a function. Ensure the variable is always assigned a value *before* it's used, even if that means assigning a default value like None initially. Using `global` or `nonlocal` keywords appropriately if the variable is intended to be accessed/modified in a different scope is also crucial.

Related Issues

Real GitHub issues where developers encountered this error:

Timeline

First reported:Feb 16, 2025
Last reported:Feb 16, 2025

Need More Help?

View the full changelog and migration guides for Requests

View Requests Changelog