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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user