This commit is contained in:
1 parent
5d0ab2ebd0
commit
e2cfcfad34
3 files changed
+56
-48
No files matched your search
@@ -0,0 +1,15 @@
|
||||
from aiohttp import ClientSession, ClientTimeout
|
||||
from app.config import CUSTOM_USER_AGENT
|
||||
|
||||
async def fetch_url(url: str) -> tuple[str, int]:
|
||||
"""
|
||||
Fetch a URL using aiohttp and return the content and status code
|
||||
"""
|
||||
timeout = ClientTimeout(total=30) # 30 second timeout
|
||||
async with ClientSession(timeout=timeout) as session:
|
||||
headers = {
|
||||
'User-Agent': CUSTOM_USER_AGENT
|
||||
}
|
||||
async with session.get(url, headers=headers) as response:
|
||||
content = await response.text()
|
||||
return content, response.status
|
||||
Reference in new issue
Block a user