From 240da44f2fcc78eedced2b994783a7511d91a548 Mon Sep 17 00:00:00 2001 From: deflax Date: Sat, 8 Feb 2025 03:41:34 +0200 Subject: [PATCH] test httpx --- src/discordbot/discordbot.py | 9 +++------ src/discordbot/requirements.txt | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/discordbot/discordbot.py b/src/discordbot/discordbot.py index a524ee5..9ebf3cb 100644 --- a/src/discordbot/discordbot.py +++ b/src/discordbot/discordbot.py @@ -3,7 +3,7 @@ import os import asyncio import logging import subprocess -import requests +import httpx import discord from discord.ext.commands import Bot, has_permissions, CheckFailure, has_role, MissingRole from apscheduler.schedulers.asyncio import AsyncIOScheduler @@ -126,13 +126,10 @@ async def stop_error(ctx, error): async def query_playhead(): head_url = f'https://{scheduler_hostname}/playhead' try: - if requests.get(head_url).status_code == 200: - response = requests.get(head_url) - response.raise_for_status() + async with httpx.AsyncClient() as client: + response = await client.get(head_url) playhead = response.json() logger_discord.info(f'Querying playhead at {head_url}') - else: - logger_discord.error('Cannot connect to the playhead!') except Exception as e: logger_discord.error('Cannot connect to the playhead!') logger_discord.error(e) diff --git a/src/discordbot/requirements.txt b/src/discordbot/requirements.txt index 78fd84d..ad2d9d3 100644 --- a/src/discordbot/requirements.txt +++ b/src/discordbot/requirements.txt @@ -1,5 +1,5 @@ APScheduler==3.11.0 -requests==2.32.3 +httpx==0.28.1 discord.py==2.4.0 audioop-lts==0.2.1 python-ffmpeg==2.0.12 \ No newline at end of file