mirror of
https://github.com/kuhyx/signal-bot.git
synced 2026-11-28 21:29:20 +01:00
fix: the release preview sends the app's User-Agent, which Commons requires
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
31ef21c763
commit
a078383b60
@ -33,6 +33,7 @@ from typing import Final
|
|||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
from signal_bot.announce import render
|
from signal_bot.announce import render
|
||||||
|
from signal_bot.app import HTTP_TIMEOUT_SECONDS, USER_AGENT
|
||||||
from signal_bot.changelog import load, since
|
from signal_bot.changelog import load, since
|
||||||
from signal_bot.config_env import load_config
|
from signal_bot.config_env import load_config
|
||||||
from signal_bot.http_client import ImageFetcher
|
from signal_bot.http_client import ImageFetcher
|
||||||
@ -109,9 +110,16 @@ async def send_preview(group: str, ordinal: int, *, print_only: bool) -> None:
|
|||||||
if print_only:
|
if print_only:
|
||||||
sys.stdout.write("== not sent (--print-only)\n")
|
sys.stdout.write("== not sent (--print-only)\n")
|
||||||
return
|
return
|
||||||
|
sys.stdout.flush()
|
||||||
|
|
||||||
config = load_config()
|
config = load_config()
|
||||||
async with httpx.AsyncClient(timeout=60.0) as client:
|
# The app's client, headers and all: Wikimedia answers 403 to httpx's
|
||||||
|
# default User-Agent, so a bare client here would fail exactly where the
|
||||||
|
# bot succeeds -- which is the opposite of what a preview is for.
|
||||||
|
async with httpx.AsyncClient(
|
||||||
|
timeout=HTTP_TIMEOUT_SECONDS,
|
||||||
|
headers={"User-Agent": USER_AGENT},
|
||||||
|
) as client:
|
||||||
group_id = await group_id_for(client, config.groups_url, group)
|
group_id = await group_id_for(client, config.groups_url, group)
|
||||||
portraits = PortraitCache(ImageFetcher(client), config.commons_api_url)
|
portraits = PortraitCache(ImageFetcher(client), config.commons_api_url)
|
||||||
image = await portraits.get_base64(pope)
|
image = await portraits.get_base64(pope)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user