mirror of https://github.com/miaowware/qrm2.git
First steps for move from aiohttp to httpx
This commit is contained in:
parent
9368ccd9e2
commit
fdd8267e31
13
common.py
13
common.py
|
@ -18,6 +18,7 @@ from types import SimpleNamespace
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
import httpx
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
import discord.ext.commands as commands
|
import discord.ext.commands as commands
|
||||||
|
@ -125,12 +126,16 @@ class ImagesGroup(collections.abc.Mapping):
|
||||||
|
|
||||||
class BotHTTPError(Exception):
|
class BotHTTPError(Exception):
|
||||||
"""Raised whan a requests fails (status != 200) in a command."""
|
"""Raised whan a requests fails (status != 200) in a command."""
|
||||||
def __init__(self, response: aiohttp.ClientResponse):
|
def __init__(self, response: aiohttp.ClientResponse | httpx.Response):
|
||||||
msg = f"Request failed: {response.status} {response.reason}"
|
if isinstance(response, aiohttp.ClientResponse):
|
||||||
|
self.status = response.status
|
||||||
|
self.reason = response.reason
|
||||||
|
else:
|
||||||
|
self.status = response.status_code
|
||||||
|
self.reason = response.reason_phrase
|
||||||
|
msg = f"Request failed: {self.status} {self.reason}"
|
||||||
super().__init__(msg)
|
super().__init__(msg)
|
||||||
self.response = response
|
self.response = response
|
||||||
self.status = response.status
|
|
||||||
self.reason = response.reason
|
|
||||||
|
|
||||||
|
|
||||||
# --- Converters ---
|
# --- Converters ---
|
||||||
|
|
3
main.py
3
main.py
|
@ -16,6 +16,7 @@ from datetime import datetime, time
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import httpx
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
|
@ -69,6 +70,8 @@ bot.qrm = SimpleNamespace()
|
||||||
# Let's store stuff here.
|
# Let's store stuff here.
|
||||||
bot.qrm.connector = connector
|
bot.qrm.connector = connector
|
||||||
bot.qrm.debug_mode = debug_mode
|
bot.qrm.debug_mode = debug_mode
|
||||||
|
# TODO: Add code to close the client
|
||||||
|
bot.qrm.httpx_client = httpx.AsyncClient()
|
||||||
|
|
||||||
|
|
||||||
# --- Commands ---
|
# --- Commands ---
|
||||||
|
|
Loading…
Reference in New Issue