From 0757fcc4519bc1ad13a9ab825847fb317916f797 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 18 Nov 2022 10:16:29 +0530 Subject: [PATCH] Dont fail on github responses without JSON payloads --- publish.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/publish.py b/publish.py index e6bad330a..52a01262a 100755 --- a/publish.py +++ b/publish.py @@ -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)