From a522e90016732741cb0add397ad67b98558f75f7 Mon Sep 17 00:00:00 2001 From: Sixu Hu Date: Sat, 6 Feb 2021 17:32:17 +0800 Subject: [PATCH] Added User-Agent request header --- main.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 5ae793f..fb2b953 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ import websocket -from urllib.request import urlopen +from urllib.request import urlopen, Request import json import subprocess import os.path @@ -37,12 +37,15 @@ def get_picture(appid): if os.path.isfile(path): return imgPath else: - r = json.loads(urlopen("https://{}/application?token={}".format(domain, token)).read()) + req = Request("https://{}/application?token={}".format(domain, token)) + req.add_header("User-Agent", "Mozilla/5.0") + r = json.loads(urlopen(req).read()) for i in r: if i['id'] == appid: with open(imgPath, "wb") as f: - url = urlopen("https://{}/{}?token={}".format(domain, i['image'], token)) - f.write(url.read()) + req = Request("https://{}/{}?token={}".format(domain, i['image'], token)) + req.add_header("User-Agent", "Mozilla/5.0") + f.write(urlopen(req).read()) return imgPath def send_notification(message):