Browse Source

Merge pull request 'clean up the bad requests' (#6) from fix/bad-requests into ApiRestructure

Reviewed-on: https://git.chapo.chat/chapo-collective/hexbear-python/pulls/6
ApiRestructure
ScreamoBMO 11 months ago
parent
commit
5965b62c2c
  1. 5
      hexbear/v1/lib.py
  2. 6
      main.py

5
hexbear/v1/lib.py

@ -64,11 +64,10 @@ async def request(
key: (
str(value).lower() # Why the fuck does requests not automtically make booleans lowercase?
if type(value) == bool
else 'undefined'
if value is None
else value
)
for key, value in payload._asdict().items()
if value is not None
}
url = f'{base_url}{endpoint}'
if method not in ('get', 'put', 'post'):
@ -76,7 +75,7 @@ async def request(
async with aiohttp.ClientSession() as session:
async with (session.get(url, params=payload) if method == 'get'
else session.put(url, data=payload) if method == 'put'
else session.post(url, data=payload)
else session.post(url, json=payload)
) as response:
try:
response.raise_for_status()

6
main.py

@ -9,12 +9,12 @@ async def main():
site = response.unwrap()
print(site.site.name)
request = await api.user.LoginRequest(
request = api.user.LoginRequest(
username_or_email='KarenStever',
password='KarenStever'
)
response = api.user.login(request)
response = await api.user.login(request)
print(response)
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.run_until_complete(main())
Loading…
Cancel
Save