Skip to content

Commit

Permalink
wrapped _urlopen_with_retry into with to close the response once read
Browse files Browse the repository at this point in the history
  • Loading branch information
antikus committed Oct 20, 2023
1 parent 06918fb commit ff8d128
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions railib/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,14 @@ def _request_access_token(ctx: Context, url: str) -> AccessToken:
data=data,
)
_print_request(req)
rsp = _urlopen_with_retry(req, ctx.retries)
result = json.loads(rsp.read())
token = result.get(ACCESS_KEY_TOKEN_KEY, None)

if token is not None:
expires_in = result.get(EXPIRES_IN_KEY, None)
scope = result.get(SCOPE, None)
return AccessToken(token, scope, expires_in)
with _urlopen_with_retry(req, ctx.retries) as rsp:
result = json.loads(rsp.read())
token = result.get(ACCESS_KEY_TOKEN_KEY, None)

if token is not None:
expires_in = result.get(EXPIRES_IN_KEY, None)
scope = result.get(SCOPE, None)
return AccessToken(token, scope, expires_in)

raise Exception("failed to get the access token")

Expand Down

0 comments on commit ff8d128

Please sign in to comment.