set User-Agent when accessing external resources (#2100)

* set User-Agent when accessing external resources

* refactor User-Agent into settings.user_agent
This commit is contained in:
Pavol Rusnak
2023-11-30 12:54:07 +00:00
committed by GitHub
parent 992e3bfb9a
commit 62b0e3fe89
16 changed files with 70 additions and 43 deletions
+2 -1
View File
@@ -179,7 +179,8 @@ class NodeRank(BaseModel):
)
async def api_get_1ml_stats(node: Node = Depends(require_node)) -> Optional[NodeRank]:
node_id = await node.get_id()
async with httpx.AsyncClient() as client:
headers = {"User-Agent": settings.user_agent}
async with httpx.AsyncClient(headers=headers) as client:
r = await client.get(url=f"https://1ml.com/node/{node_id}/json", timeout=15)
try:
r.raise_for_status()