From f0136b89f1f8a11347563bda9190d5cf8d614e90 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Sun, 26 Jan 2025 17:12:25 -0600 Subject: [PATCH] Fixed some calls by adding user agents --- setup.py | 2 +- updater/core.py | 12 ++++++++---- updater/wxupdater.py | 4 +++- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index eef4252..9d462ab 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup setup(name="updater", -version="0.3.0", +version="0.3.1", author="MCVSoftware", author_email="support@mcvsoftware.com", url="https://github.com/mcvsoftware/updater", diff --git a/updater/core.py b/updater/core.py index 89e15f7..e70ed5c 100644 --- a/updater/core.py +++ b/updater/core.py @@ -38,6 +38,8 @@ class UpdaterCore(object): self.current_version = current_version self.app_name = app_name self.password = password + self.update_version = None + self.update_description = None def get_update_information(self) -> Dict[str, Any]: """ Calls the provided URL endpoint and returns information about the available update sent by the server. The format should adhere to the json specifications for updates. @@ -46,8 +48,10 @@ class UpdaterCore(object): :rtype: dict """ - response = urllib.request.urlopen(self.endpoint) - data: str = response.read() + headers = {"User-Agent": f"{self.app_name}/{self.current_version}"} + req = urllib.request.Request(self.endpoint, headers=headers) + with urllib.request.urlopen(req) as response: + data: str = response.read() content: Dict[str, Any] = json.loads(data) return content @@ -97,8 +101,8 @@ class UpdaterCore(object): def _download_callback(transferred_blocks, block_size, total_size): total_downloaded = transferred_blocks*block_size pub.sendMessage("updater.update-progress", total_downloaded=total_downloaded, total_size=total_size) - - filename, headers = urllib.request.urlretrieve(update_url, update_destination, _download_callback) + request = urllib.request.Request(update_url, headers={"User-Agent": f"{self.app_name}/{self.current_version}"}) + filename, headers = urllib.request.urlretrieve(request, update_destination, _download_callback) log.debug("Update downloaded") return update_destination diff --git a/updater/wxupdater.py b/updater/wxupdater.py index ec065c2..cf24f84 100644 --- a/updater/wxupdater.py +++ b/updater/wxupdater.py @@ -112,7 +112,7 @@ class WXUpdater(core.UpdaterCore): :returns: True if user wants to download the update, False otherwise. :rtype: bool """ - dialog = wx.MessageDialog(None, self.new_update_msg, self.new_update_title, style=wx.YES|wx.NO|wx.ICON_WARNING) + dialog = wx.MessageDialog(None, self.new_update_msg.format(app_name=self.app_name, update_version=self.update_version, update_description=self.update_description), self.new_update_title.format(app_name=self.app_name), style=wx.YES|wx.NO|wx.ICON_WARNING) response = dialog.ShowModal() dialog.Destroy() if response == wx.ID_YES: @@ -156,6 +156,8 @@ class WXUpdater(core.UpdaterCore): version_data = self.get_version_data(update_info) if version_data[0] == False: return None + self.update_version = version_data[0] + self.update_description = version_data[1] response = self.on_new_update_available() if response == False: return None