From 7c75ca678c0efb6a29bc843e4d5c6ca7c7f2ce3f Mon Sep 17 00:00:00 2001 From: spla Date: Tue, 24 Aug 2021 19:11:33 +0200 Subject: [PATCH] Added user agent --- fetchservers.py | 4 +++- getpeers.py | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/fetchservers.py b/fetchservers.py index 1a89af6..e1d2cee 100644 --- a/fetchservers.py +++ b/fetchservers.py @@ -79,8 +79,10 @@ async def getsoft(server): url = 'https://' + server + user_agent = {'User-agent': 'Mozilla/5.0'} + timeout = aiohttp.ClientTimeout(total=3) - async with aiohttp.ClientSession(timeout=timeout) as session: + async with aiohttp.ClientSession(timeout=timeout, headers=user_agent) as session: for api in apis: try: async with session.get(url + api) as response: diff --git a/getpeers.py b/getpeers.py index cd60fe8..0146cea 100644 --- a/getpeers.py +++ b/getpeers.py @@ -50,7 +50,9 @@ def get_peers(peer): try: - response = requests.get('https://' + peer + peers_api, timeout=2) + user_agent = {'User-agent': 'Mozilla/5.0'} + + response = requests.get('https://' + peer + peers_api, headers = user_agent, timeout=3) response_json = response.json() @@ -126,7 +128,9 @@ if __name__ == '__main__': world_peers = [] - res = requests.get('https://' + mastodon_hostname + peers_api) + user_agent = {'User-agent': 'Mozilla/5.0'} + + res = requests.get('https://' + mastodon_hostname + peers_api, headers = user_agent, timeout=3) hostname_peers = res.json()