Skip to content

UnboundLocalError in request_class.py #123

Closed
@vgreg

Description

@vgreg

Python 3.11
Habanero 1.2.3

I'm getting the following error on line 164 of request_class.py: UnboundLocalError: cannot access local variable 'r' where it is not associated with a value.

It seem that you can reach that line (check_json(r)) with r undefined if requests.get() raises a RequestException before returning. Because the exception is caught and printed, the code continues with r still undefined.

def _req(self, payload, should_warn):
try:
r = requests.get(
self._url(),
params=payload,
headers=make_ua(self.mailto, self.ua_string),
)
r.raise_for_status()
except requests.exceptions.HTTPError:
try:
f = r.json()
raise RequestError(r.status_code, f["message"][0]["message"])
except:
if should_warn:
mssg = "%s: %s" % (r.status_code, r.reason)
warnings.warn(mssg)
return None
else:
r.raise_for_status()
except requests.exceptions.RequestException as e:
print(e)
check_json(r)
return r.json()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions