- commit
- d3729210d42b564168c78ebb0bea8325df05e604
- parent
- 2671a426ed3f41e3166d2c77d136718be420941e
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2025-09-21 04:05
wip: work around reddit block aiohttp sets ALPN on SSL context which seems to make a difference
Diffstat
| M | neddit.py | 10 | ++++++++-- |
1 files changed, 8 insertions, 2 deletions
diff --git a/neddit.py b/neddit.py
@@ -7,10 +7,14 @@ from pathlib import Path 7 7 8 8 import aiohttp 9 9 import jinja2 -1 10 import ssl 10 11 from aiohttp import web 11 12 from yarl import URL 12 13 13 14 BASE_DIR = Path(__file__).parent -1 15 HEADERS = { -1 16 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:140.0) Gecko/20100101 Firefox/140.0', -1 17 } 14 18 15 19 env = jinja2.Environment( 16 20 loader=jinja2.FileSystemLoader(BASE_DIR / 'templates'), @@ -95,8 +99,9 @@ async def fetch(url, **params): 95 99 async with aiohttp.ClientSession() as session: 96 100 async with session.get( 97 101 url,98 -1 headers={'User-agent': 'neddit'},-1 102 headers=HEADERS, 99 103 params={**params, 'raw_json': 1}, -1 104 ssl=ssl.create_default_context(), 100 105 ) as response: 101 106 raise_for_status(response) 102 107 return await response.json() @@ -106,8 +111,9 @@ async def check_redirect(url): 106 111 async with aiohttp.ClientSession() as session: 107 112 async with session.get( 108 113 url,109 -1 headers={'User-agent': 'neddit'},-1 114 headers=HEADERS, 110 115 allow_redirects=False, -1 116 ssl=ssl.create_default_context(), 111 117 ) as response: 112 118 raise_for_status(response) 113 119 if 'Location' in response.headers: