From 1177ebaf4693affb28c327220b8a55493dc04ed0 Mon Sep 17 00:00:00 2001 From: Nanda Scott Date: Thu, 15 Feb 2018 15:03:18 -0500 Subject: [PATCH] I think I fixed the issue with async now. --- docs/Cards_Classes.md | 2 -- scrython/cards/cards_object.py | 16 ++++++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/docs/Cards_Classes.md b/docs/Cards_Classes.md index ab98313..8421d97 100644 --- a/docs/Cards_Classes.md +++ b/docs/Cards_Classes.md @@ -120,5 +120,3 @@ Get a list of potential autocompletion phrases. Example usage: card = scrython.cards.Autocomplete(query="Ezuri") - - diff --git a/scrython/cards/cards_object.py b/scrython/cards/cards_object.py index 9fbe00f..de220dc 100644 --- a/scrython/cards/cards_object.py +++ b/scrython/cards/cards_object.py @@ -12,21 +12,21 @@ class CardsObject(object): self.encodedParams = urllib.parse.urlencode(self.params) self._url = 'https://api.scryfall.com/' + _url + "&" + self.encodedParams #Find a fix for this later - loop = asyncio.get_event_loop() - self.session = aiohttp.ClientSession(loop=loop) - async def getRequest(url, **kwargs): - async with self.session.get(url, **kwargs) as response: + async def getRequest(client, url, **kwargs): + async with client.get(url, **kwargs) as response: return await response.json() - self.scryfallJson = loop.run_until_complete(getRequest(url = self._url)) + async def main(loop): + async with aiohttp.ClientSession(loop=loop) as client: + self.scryfallJson = await getRequest(client, self._url) + + loop = asyncio.get_event_loop() + loop.run_until_complete(main(loop)) if self.scryfallJson['object'] == 'error': - self.session.close() raise Exception(self.scryfallJson['details']) - self.session.close() - def __checkForKey(self, key): try: return self.scryfallJson[key]