Skip to content

Commit

Permalink
fix aiohttp
Browse files Browse the repository at this point in the history
  • Loading branch information
tcprescott committed Jul 16, 2021
1 parent 6fbde14 commit 8e682f5
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions pyz3r/alttpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ def __init__(
self.settings = None
self.baseurl = baseurl
self.auth = aiohttp.BasicAuth(login=username, password=password) if username and password else None
self.http = aiohttp.ClientSession(raise_for_status=True)

@classmethod
async def generate(cls, settings, endpoint='/api/randomizer', **kwargs):
Expand All @@ -45,7 +44,7 @@ async def generate_game(self, settings, endpoint):
self.settings = settings
for _ in range(0, 5):
try:
async with self.http.post(url=self.uri(endpoint), json=settings, auth=self.auth) as resp:
async with aiohttp.request(method='post', url=self.uri(endpoint), json=settings, auth=self.auth, raise_for_status=True) as resp:
req = await resp.json()
self.data = req
return req
Expand All @@ -57,7 +56,7 @@ async def generate_game(self, settings, endpoint):
async def retrieve_game(self, hash_id):
for _ in range(0, 5):
try:
async with self.http.get(url=self.uri('/hash/' + hash_id), auth=self.auth) as resp:
async with aiohttp.request(method='get', url=self.uri('/hash/' + hash_id), auth=self.auth, raise_for_status=True) as resp:
req = await resp.json(content_type="text/html")
self.data = req
return req
Expand All @@ -75,7 +74,7 @@ async def randomizer_settings(self):
Returns:
dict -- dictonary of valid settings that can be used
"""
async with self.http.get(url=self.baseurl + '/randomizer/settings', auth=self.auth) as resp:
async with aiohttp.request(method='get', url=self.baseurl + '/randomizer/settings', auth=self.auth, raise_for_status=True) as resp:
settings = await resp.json()
return settings

Expand All @@ -85,12 +84,12 @@ async def customizer_settings(self):
Returns:
dict -- dictonary of valid settings that can be used
"""
async with self.http.get(url=self.baseurl + '/customizer/settings', auth=self.auth) as resp:
async with aiohttp.request(method='get', url=self.baseurl + '/customizer/settings', auth=self.auth, raise_for_status=True) as resp:
settings = await resp.json()
return settings

async def find_daily_hash(self):
async with self.http.get(url=f'{self.baseurl}/api/daily', auth=self.auth) as resp:
async with aiohttp.request(method='get', url=f'{self.baseurl}/api/daily', auth=self.auth, raise_for_status=True) as resp:
daily = await resp.json()
return daily['hash']

Expand Down Expand Up @@ -136,7 +135,7 @@ async def get_patch_base(self):
Returns:
bytes -- a bytes-like object representing a BPS patch
"""
async with self.http.get(url=self.uri("/api/h/" + self.hash), auth=self.auth) as resp:
async with aiohttp.request(method='get', url=self.uri("/api/h/" + self.hash), auth=self.auth, raise_for_status=True) as resp:
seed_settings = await resp.json()

cachedbpstmp = os.path.join(tempfile.gettempdir(), "pyz3r", "bps")
Expand All @@ -146,7 +145,7 @@ async def get_patch_base(self):
with open(cachedbpsfile, "rb") as f:
req_patch = f.read()
except (FileNotFoundError, PermissionError):
async with self.http.get(url=self.baseurl + seed_settings['bpsLocation'], auth=self.auth) as resp:
async with aiohttp.request(method='get', url=self.baseurl + seed_settings['bpsLocation'], auth=self.auth, raise_for_status=True) as resp:
req_patch = await resp.read()

try:
Expand Down Expand Up @@ -220,7 +219,7 @@ async def get_sprite(self, name):
Returns:
list -- a list of bytes depicting a SPR or ZSPR file
"""
async with self.http.get(url=self.baseurl + '/sprites', auth=self.auth) as resp:
async with aiohttp.request(method='get', url=self.baseurl + '/sprites', auth=self.auth, raise_for_status=True) as resp:
sprites = await resp.json()
try:
spriteinfo = next(
Expand All @@ -229,7 +228,7 @@ async def get_sprite(self, name):
raise Pyz3rException(
f"Sprite {name} does not exist on {self.base_url}.")
try:
async with self.http.get(url=spriteinfo["file"]) as resp:
async with aiohttp.request(method='get', url=spriteinfo["file"], raise_for_status=True) as resp:
spritedata = await resp.read()
except Exception as e:
raise Pyz3rException(
Expand Down

0 comments on commit 8e682f5

Please sign in to comment.