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