From 80772d93746943c8037300f6aa0f324969f5ce71 Mon Sep 17 00:00:00 2001 From: Dan Hess Date: Wed, 31 Mar 2021 23:34:34 -0800 Subject: [PATCH] Provide a way to provide json data directly --- cogs/japanese.py | 2 +- utils/utilities.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/cogs/japanese.py b/cogs/japanese.py index 46d7c91..05a7a09 100644 --- a/cogs/japanese.py +++ b/cogs/japanese.py @@ -72,7 +72,7 @@ query ($name: String) { url = "https://graphql.anilist.co" payload = {"query": query, "variables": {"name": username}} - response = await request(url, method="POST", payload=payload) + response = await request(url, method="POST", json_data=payload) # Anilist API is broken and doesn't filter correctly, guess we have to do that ourselves data = [] diff --git a/utils/utilities.py b/utils/utilities.py index a782627..c478b3b 100644 --- a/utils/utilities.py +++ b/utils/utilities.py @@ -29,6 +29,7 @@ async def request( *, headers=None, payload=None, + json_data=None, method="GET", attr="json", force_content_type_json=False, @@ -45,7 +46,9 @@ async def request( # Create the session with our headeres async with aiohttp.ClientSession(headers=headers) as session: # Make the request, based on the method, url, and paramaters given - async with session.request(method, url, params=payload) as response: + async with session.request( + method, url, params=payload, json=json_data + ) as response: # If the request wasn't successful, re-attempt if response.status != 200: continue