From 04da5bc5f6d9fed74995b52ea2ad5ff54612c807 Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Tue, 13 Jun 2023 22:00:51 +0200 Subject: [PATCH] diff path network --- lib/WPImport.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lib/WPImport.py b/lib/WPImport.py index 4bf897d..28f0542 100644 --- a/lib/WPImport.py +++ b/lib/WPImport.py @@ -445,21 +445,27 @@ class WPimport: if len(img) > 0: href_a = i.get("href") href_img = img[0].get("src") + href_a_o = urlparse(href_a) + href_img_o = urlparse(href_img) new_img["old_src"]=href_img new_img["old_href"]=href_a try: - page_img = self._request.get(href_img) + if len(href_img_o.netloc) > 0: + page_img = self._request.get(href_img) - if page_img.status_code == 404: - href_img = href_a - try: - page_img = self._request.get(href_a) - except ConnectionError as err: - self._logger.error("{0} : Connection error for get image : {1}".format(self._name, err)) - exit(1) - except Exception as err: - self._logger.error("{0} : Exception error for get image : {1}".format(self._name, err)) - exit(1) + if page_img.status_code == 404: + href_img = href_a + try: + page_img = self._request.get(href_a) + except ConnectionError as err: + self._logger.error("{0} : Connection error for get image : {1}".format(self._name, err)) + exit(1) + except Exception as err: + self._logger.error("{0} : Exception error for get image : {1}".format(self._name, err)) + exit(1) + else: + if os.path.exists(href_img): + page_img = open(href_img, "r") self._logger.debug("{0} : Status code for image {1} : {2}".format(self._name, href_img, page_img.status_code)) if page_img.status_code == 200: media=self._addOrUpdateMedia(href_img, page_img)