mirror of
https://github.com/myned/modufur.git
synced 2024-12-25 06:37:29 +00:00
Fixed r.read() raising ClientConnectionError
Context manager was closing the request before methods could be run on it
This commit is contained in:
parent
5fbcc3ac4b
commit
9a1d225b9b
4 changed files with 20 additions and 7 deletions
|
@ -32,6 +32,7 @@ class Bot:
|
||||||
# loop = self.bot.loop.all_tasks()
|
# loop = self.bot.loop.all_tasks()
|
||||||
# for task in loop:
|
# for task in loop:
|
||||||
# task.cancel()
|
# task.cancel()
|
||||||
|
u.close()
|
||||||
await self.bot.logout()
|
await self.bot.logout()
|
||||||
await self.bot.close()
|
await self.bot.close()
|
||||||
print('\n/ / / / / / / / / / / /\nD I S C O N N E C T E D\n\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\\n')
|
print('\n/ / / / / / / / / / / /\nD I S C O N N E C T E D\n\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\\n')
|
||||||
|
@ -48,6 +49,7 @@ class Bot:
|
||||||
# loop = self.bot.loop.all_tasks()
|
# loop = self.bot.loop.all_tasks()
|
||||||
# for task in loop:
|
# for task in loop:
|
||||||
# task.cancel()
|
# task.cancel()
|
||||||
|
u.close()
|
||||||
await self.bot.logout()
|
await self.bot.logout()
|
||||||
await self.bot.close()
|
await self.bot.close()
|
||||||
os.execl(sys.executable, 'python3', 'run.py')
|
os.execl(sys.executable, 'python3', 'run.py')
|
||||||
|
|
|
@ -41,6 +41,7 @@ async def on_ready():
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_error(error):
|
async def on_error(error):
|
||||||
|
u.close()
|
||||||
await bot.logout()
|
await bot.logout()
|
||||||
await bot.close()
|
await bot.close()
|
||||||
print('\n! ! ! ! !\nE R R O R : {}\n! ! ! ! !\n'.format(error), file=sys.stderr)
|
print('\n! ! ! ! !\nE R R O R : {}\n! ! ! ! !\n'.format(error), file=sys.stderr)
|
||||||
|
|
|
@ -6,10 +6,10 @@ from utils import utils as u
|
||||||
|
|
||||||
|
|
||||||
async def check_match(url):
|
async def check_match(url):
|
||||||
r = await u.fetch('http://iqdb.harry.lu/?url={}'.format(url))
|
content = await u.fetch('http://iqdb.harry.lu', params={'url': url})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
value = BeautifulSoup(await r.read(), 'html.parser').find_all('a')[1].get('href')
|
value = BeautifulSoup(content, 'html.parser').find_all('a')[1].get('href')
|
||||||
except IndexError:
|
except IndexError:
|
||||||
raise exc.MatchError
|
raise exc.MatchError
|
||||||
|
|
||||||
|
|
|
@ -68,10 +68,20 @@ async def clear(obj, interval=10 * 60, replace=None):
|
||||||
obj = replace
|
obj = replace
|
||||||
asyncio.sleep(interval)
|
asyncio.sleep(interval)
|
||||||
|
|
||||||
|
session = aiohttp.ClientSession()
|
||||||
|
|
||||||
|
|
||||||
|
def close():
|
||||||
|
global session
|
||||||
|
|
||||||
|
if session:
|
||||||
|
session.close()
|
||||||
|
|
||||||
|
|
||||||
async def fetch(url, *, params={}, json=False):
|
async def fetch(url, *, params={}, json=False):
|
||||||
async with aiohttp.ClientSession() as session:
|
global session
|
||||||
|
|
||||||
async with session.get(url, params=params, headers={'user-agent': 'Modumind/0.0.1 (Myned)'}) as r:
|
async with session.get(url, params=params, headers={'user-agent': 'Modumind/0.0.1 (Myned)'}) as r:
|
||||||
if json is True:
|
if json is True:
|
||||||
return await r.json()
|
return await r.json()
|
||||||
return r
|
return await r.read()
|
||||||
|
|
Loading…
Reference in a new issue