Skip to content

Commit 36263d0

Browse files
webbnhportante
authored andcommitted
Handle response payloads which are not JSON in generate_token.py (#2862)
Also, more gracefully handle payloads which are missing the authorization token.
1 parent 0a9d5ea commit 36263d0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/pbench/cli/agent/commands/generate_token.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""pbench-generate-token"""
22

3+
from json import JSONDecodeError
4+
35
import click
46
import requests
57

@@ -30,8 +32,12 @@ def execute(self):
3032
except requests.exceptions.ConnectionError as exc:
3133
raise RuntimeError(f"Cannot connect to '{uri}'") from exc
3234

33-
payload = response.json()
34-
if response.ok:
35+
try:
36+
payload = response.json()
37+
except JSONDecodeError:
38+
payload = {"message": response.text}
39+
40+
if response.ok and "auth_token" in payload:
3541
click.echo(payload["auth_token"])
3642
return 0
3743

0 commit comments

Comments
 (0)