[1]:
from dunderlab.api import aioAPI
from dunderlab.api.utils import JSON
API = 'http://localhost:8000/timescaledbapp/'
API_TOKEN = API + 'api/token/'
API_TOKEN_VERIFY = API_TOKEN + 'verify/'
[2]:
api = aioAPI(API)
[3]:
superuser_token = await api.token(username = 'yeison', password= 'electronica')
superuser_token
[3]:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjk2ODc5Mjk3LCJpYXQiOjE2OTY3OTI4OTcsImp0aSI6Ijc5YzI4MTU3YWYyZTQ0NzZiMDZjYzY1NGU4MDdhY2Q0IiwidXNlcl9pZCI6MX0.4wy7Yb9HwV9N22Ugb-0AvgaKeZgfzOgZ5hiFN1xxVgg'
[4]:
newuser_token = await api.token(username = 'new_user', password= 'electronica')
newuser_token
[4]:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbl90eXBlIjoiYWNjZXNzIiwiZXhwIjoxNjk2ODc5Mjk3LCJpYXQiOjE2OTY3OTI4OTcsImp0aSI6ImJhY2MxOTIyZDA1YjQ2MGU5OTFkMjM1MjBmYzRmODljIiwidXNlcl9pZCI6Mn0.zJrWjw4b-0yg6lOEjLxTYlDjZn6R-9TbL7AogxbGdo8'
[6]:
await api.token_verify(token = newuser_token)
[6]:
{'detail': 'Token is valid'}
[10]:
api = aioAPI(API, token=superuser_token)
source_retrieve = await api.source.get()
JSON(source_retrieve)
{
"count": 2,
"next": null,
"previous": null,
"results": [
{
"label": "Test.v1",
"name": "Test Database",
"location": "Eje Cafetero",
"device": "None",
"protocol": "None",
"version": "0.1",
"description": "Sample database for TimeScaleDBApp",
"created": "2023-07-23T01:09:10.708790Z",
},
{
"label": "esp32_core2",
"name": "ESP32 Core2",
"location": "GCPDS",
"device": "ESP32 Core2",
"protocol": "WiFi API",
"version": "0.1",
"description": "Latency measurement",
"created": "2023-08-27T16:36:05.868233Z",
}],
}
[255]:
api = aioAPI(API, token=newuser_token)
source_retrieve = await api.source.get()
JSON(source_retrieve)
/home/yeison/.local/lib/python3.11/site-packages/aiohttp/resolver.py:33: RuntimeWarning: coroutine 'aioAPI.endpoints' was never awaited
infos = await self._loop.getaddrinfo(
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
WARNING:root:Error 403: Forbidden
WARNING:root:<coroutine object ClientResponse.json at 0x7fd5d7693670>
null
[256]:
api = aioAPI(API)
source_retrieve = await api.source.get()
JSON(source_retrieve)
WARNING:root:Error 401: Unauthorized
WARNING:root:<coroutine object ClientResponse.json at 0x7fd5d7693670>
null
[ ]:
[ ]: