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