add debug message for error request

This commit is contained in:
Valentin CZERYBA 2023-04-20 20:48:37 +02:00
parent c44ffc5a86
commit 34d6cc39d2

View File

@ -44,6 +44,7 @@ class WPimport:
self._addOrUpdateFeaturedMedia(soup) self._addOrUpdateFeaturedMedia(soup)
else: else:
self._logger.error("Connection error with status code : {0}".format(r.status_code)) self._logger.error("Connection error with status code : {0}".format(r.status_code))
self._logger.debug(r.content)
def fromDirectory(self, directory): def fromDirectory(self, directory):
@ -135,14 +136,22 @@ class WPimport:
self._logger.info("Ajout media featured : {0}".format(r.json()["title"]["raw"])) self._logger.info("Ajout media featured : {0}".format(r.json()["title"]["raw"]))
else: else:
self._logger.error("Connection error with status code : {0}".format(r.status_code)) self._logger.error("Connection error with status code : {0}".format(r.status_code))
self._logger.debug(r.content)
else: else:
self._logger.info("Aucun media trouvé pour {0}".format(h2)) self._logger.info("Aucun media trouvé pour {0}".format(h2))
else: else:
self._logger.error("Connection error with status code : {0}".format(page.status_code)) self._logger.error("Connection error with status code : {0}".format(page.status_code))
self._logger.debug(page.content)
else: else:
self._logger.error("Connection error with status code : {0}".format(page.status_code)) self._logger.error("Connection error with status code : {0}".format(page.status_code))
self._logger.debug(page.content)
else: else:
self._logger.error("Connection error with status code : {0}".format(page.status_code)) self._logger.error("Connection error with status code : {0}".format(page.status_code))
self._logger.debug(page.content)
## Association image to post ## Association image to post
@ -158,6 +167,8 @@ class WPimport:
self._logger.info("Association d'une image à l'article {0}".format(title)) self._logger.info("Association d'une image à l'article {0}".format(title))
else: else:
self._logger.error("Connection error with status code : {0}".format(r.status_code)) self._logger.error("Connection error with status code : {0}".format(r.status_code))
self._logger.debug(r.content)
## Add or update img ## Add or update img
@ -184,6 +195,8 @@ class WPimport:
self._logger.info("Image removed {0}".format(img_name)) self._logger.info("Image removed {0}".format(img_name))
else: else:
self._logger.error("Image not removed due status code : {0}".format(r.status_code)) self._logger.error("Image not removed due status code : {0}".format(r.status_code))
self._logger.debug(r.content)
data = page.content data = page.content
img_type = "image/png" img_type = "image/png"
if img_name.split(".")[1] == "jpg" or img_name.split(".")[1] == "jpeg": if img_name.split(".")[1] == "jpg" or img_name.split(".")[1] == "jpeg":
@ -201,8 +214,12 @@ class WPimport:
media["rendered"] = res["guid"]["rendered"] media["rendered"] = res["guid"]["rendered"]
else: else:
self._logger.error("Image not added due status code : {0}".format(r.status_code)) self._logger.error("Image not added due status code : {0}".format(r.status_code))
self._logger.debug(r.content)
else: else:
self._logger.error("Connection error with status code : {0}".format(r.status_code)) self._logger.error("Connection error with status code : {0}".format(r.status_code))
self._logger.debug(r.content)
return media return media
## Add or update comment ## Add or update comment
@ -230,9 +247,12 @@ class WPimport:
self._logger.debug("Comment deleted : {0}".format(j)) self._logger.debug("Comment deleted : {0}".format(j))
else: else:
self._logger.error("Comment not deleted for {0} due status code : {1}".format(title, page.status_code)) self._logger.error("Comment not deleted for {0} due status code : {1}".format(title, page.status_code))
self._logger.debug(page.content)
else: else:
self._logger.error("Comment not listed for {0} due status code : {1}".format(title, page.status_code)) self._logger.error("Comment not listed for {0} due status code : {1}".format(title, page.status_code))
self._logger.debug(page.content)
for i in comment: for i in comment:
data = {"post": post, "content": i["content"], "date": i["date"], "author_name": i["author"], "status": "approved"} data = {"post": post, "content": i["content"], "date": i["date"], "author_name": i["author"], "status": "approved"}
@ -250,6 +270,8 @@ class WPimport:
data["parent"]=result[0]["id"] data["parent"]=result[0]["id"]
else: else:
self._logger.error("Connection error for parent comment with status code : {0}".format(page.status_code)) self._logger.error("Connection error for parent comment with status code : {0}".format(page.status_code))
self._logger.debug(page.content)
try: try:
page = self._request.post("http://{0}/wp-json/wp/v2/comments".format(self._wordpress), auth=self._basic, data=data) page = self._request.post("http://{0}/wp-json/wp/v2/comments".format(self._wordpress), auth=self._basic, data=data)
except Exception as err: except Exception as err:
@ -261,7 +283,6 @@ class WPimport:
else: else:
self._logger.error("Comment not added for {0} due status code : {1}".format(title, page.status_code)) self._logger.error("Comment not added for {0} due status code : {1}".format(title, page.status_code))
self._logger.debug(page.content) self._logger.debug(page.content)
self._logger.debug("Data : {0}".format(data))
## Check class name ## Check class name
@ -366,6 +387,8 @@ class WPimport:
list_img.append(new_img) list_img.append(new_img)
if page_img.status_code not in [200, 404]: if page_img.status_code not in [200, 404]:
self._logger.error("Connection error with status code : {0}".format(page_img.status_code)) self._logger.error("Connection error with status code : {0}".format(page_img.status_code))
self._logger.debug(page_img.content)
comment_post = self._getComment(comment) comment_post = self._getComment(comment)
@ -394,6 +417,8 @@ class WPimport:
else: else:
self._logger.error("{0} not found due status code : {1}".format(i, page.status_code)) self._logger.error("{0} not found due status code : {1}".format(i, page.status_code))
self._logger.debug(page.content)
if element_exist is False: if element_exist is False:
data = {"name": j} data = {"name": j}
@ -410,6 +435,8 @@ class WPimport:
listelement[i].append(result["id"]) listelement[i].append(result["id"])
else: else:
self._logger.error("{0} not added due status code : {1}".format(i, page.status_code)) self._logger.error("{0} not added due status code : {1}".format(i, page.status_code))
self._logger.debug(page.content)
title = articletitle[0].text title = articletitle[0].text
author = articleacreator[0].text.lower() author = articleacreator[0].text.lower()
body = articlebody[0].find_all("p") body = articlebody[0].find_all("p")
@ -438,6 +465,8 @@ class WPimport:
data["author"] = result[0]["id"] data["author"] = result[0]["id"]
else: else:
self._logger.error("Connection error with status code : {0}".format(page.status_code)) self._logger.error("Connection error with status code : {0}".format(page.status_code))
self._logger.debug(page.content)
params = {"search":title} params = {"search":title}
try: try:
@ -466,8 +495,12 @@ class WPimport:
self._linkImgPost(result["title"]["raw"], list_img, result["id"]) self._linkImgPost(result["title"]["raw"], list_img, result["id"])
else: else:
self._logger.error("Post not updated due status code : {0}".format(page.status_code)) self._logger.error("Post not updated due status code : {0}".format(page.status_code))
self._logger.debug(page.content)
else: else:
self._logger.error("Connection for update post error with status code : {0}".format(page.status_code)) self._logger.error("Connection for update post error with status code : {0}".format(page.status_code))
self._logger.debug(page.content)
if page_exist == False: if page_exist == False:
try: try:
@ -481,4 +514,5 @@ class WPimport:
self._addOrUpdateComment(result["id"], comment_post, result["title"]["raw"]) self._addOrUpdateComment(result["id"], comment_post, result["title"]["raw"])
self._linkImgPost(result["title"]["raw"], list_img, result["id"]) self._linkImgPost(result["title"]["raw"], list_img, result["id"])
else: else:
self._logger.error("Post not added due status code : {0}".format(r.status_code)) self._logger.error("Post not added due status code : {0}".format(r.status_code))
self._logger.debug(r.content)