Tutorial - Implementing Token Authentication Errors
Following along with this https://ably.com/tutorials/token-authentication and the code doesn't work. I assumed it was something I had copied incorrectly. Got the source from here and tried to run it, same errors.
When entering the username and hitting enter, server.py produces a 500 error and client also produces an error.
This is because the authentication needs to be awaited for the token to be returned in time to return to the client.
Server error:
Traceback (most recent call last): File "/Projects/ably/tutorials/venv/lib/python3.10/site-packages/web/application.py", line 280, in process return self.handle() File "/Projects/ably/tutorials/venv/lib/python3.10/site-packages/web/application.py", line 271, in handle return self._delegate(fn, self.fvars, args) File "/Projects/ably/tutorials/venv/lib/python3.10/site-packages/web/application.py", line 502, in _delegate return handle_class(f) File "/Projects/ably/tutorials/venv/lib/python3.10/site-packages/web/application.py", line 495, in handle_class return tocall(*args) File "/Projects/ably/tutorials/server.py", line 34, in GET return json.dumps(client.auth.create_token_request(token_params).to_dict()) AttributeError: 'coroutine' object has no attribute 'to_dict'
Client error:
09:38:33.437 Ably: Auth.requestToken(): token request signing call returned error; err = [t: Malformed response body from server: Unexpected token '<', "<!DOCTYPE "... is not valid JSON; statusCode=400] r @ ably.min-1.js:24
Environment details:
OSX 14.2.1
Python 3.10.3
Pip List:
Package Version
----------------- ----------
ably 2.0.3
anyio 4.2.0
certifi 2023.11.17
cheroot 10.0.0
exceptiongroup 1.2.0
h11 0.14.0
h2 4.1.0
hpack 4.0.0
httpcore 0.17.3
httpx 0.24.1
hyperframe 6.0.1
idna 3.6
jaraco.functools 4.0.0
methoddispatch 3.0.2
more-itertools 10.2.0
msgpack 1.0.7
pip 22.0.4
pyee 11.1.0
setuptools 58.1.0
sniffio 1.3.0
typing_extensions 4.9.0
web.py 0.62
websockets 10.4