1
0
Fork 0
mirror of synced 2024-06-03 11:14:33 +12:00

Corrected how to wrap the BytesIO object

This commit is contained in:
Phxntxm 2016-12-09 21:34:17 -06:00
parent 6383b0bced
commit 821f33f5d1

View file

@ -54,15 +54,12 @@ def find_command(bot, command):
async def download_image(url): async def download_image(url):
"""Returns a file-like object based on the URL provided""" """Returns a file-like object based on the URL provided"""
headers = {'User-Agent': config.user_agent} headers = {'User-Agent': config.user_agent}
try: # Simply download the image
# Simply download the image with aiohttp.ClientSession(headers=headers) as session:
with aiohttp.ClientSession(headers=headers) as session: async with session.get(url) as r:
async with session.get(url) as r: # Then wrap it in a BytesIO object, to be used like an actual file
image_bytes = r.read() image = io.BytesIO(await r.read())
# Then wrap it in a BytesIO object, to be used like an actual file return image
return io.BytesIO(image_bytes)
except:
return
async def update_records(key, winner, loser): async def update_records(key, winner, loser):
# We're using the Harkness scale to rate # We're using the Harkness scale to rate