I have been noticing an issue with the return of JSON data with Ally. Be aware I've been running a home-brew API, but noticed your code would return the same issue, so I'm adding it to help out.
Lately, I have been receiving intermittent responses from Ally where the status_code is 200, but the content is HTML webpage code stating an error on their end, instead of JSON stating something similar. As a result, when attempting to run response.json(), I get the following traceback in a 500 error:
... Traceback to my own code ...
return resp.json()
File "[PATH]/venv/lib/python3.9/site-packages/requests/models.py", line 900, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.9/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.9/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.9/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
See if something similar is happening to you; I'd love to collaborate with you on this.
Also as an aside (but unrelated), let me know if you're OK with pull requests on this code, as my work has done some things with orders and order previews; I'm in the process of making something for orders POST to automate trades, but this issue has been slowing my progress.