Dont fail on github responses without JSON payloads

This commit is contained in:
Kovid Goyal 2022-11-18 10:16:29 +05:30
parent dd4051bfd5
commit 0757fcc451
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -347,9 +347,14 @@ def do_upload(self, url: str, path: str, desc: str, fname: str) -> requests.Resp
data=cast(IO[bytes], f))
def print_failed_response_details(self, r: requests.Response, msg: str) -> None:
print(msg, f' Status Code: {r.status_code}', file=sys.stderr)
print('JSON from response:', file=sys.stderr)
pprint.pprint(dict(r.json()), stream=sys.stderr)
print(msg, f' Status Code: {r.status_code} {r.reason}', file=sys.stderr)
try:
jr = dict(r.json())
except Exception:
pass
else:
print('JSON from response:', file=sys.stderr)
pprint.pprint(jr, stream=sys.stderr)
def fail(self, r: requests.Response, msg: str) -> None:
self.print_failed_response_details(r, msg)