Last Updated on 2022-07-16 by Clay
Problem
Today I noticed a post about LeetCode that was missing some codes. I find the article and update the content, then try to update it.
To my surprise, instead of the green successful update message as always, a red alert display: Updating failed. "Not a valid JSON response."
I found several possibilities on the Internet, but in the end, I managed to update it by mistake, so I record it as follows.
Solutions
There are several situations the problem might occur, they are:
- The editor is offline
- The URL's permalink error
- There is no connection to the website database
I have confirmed my network environment and I have successfully updated other articles. so my editor is online and connect to the website database.
As for the permalink of the URL... I'm not sure how to check this, but I checked the article settings on the right side of the editor, the Yoast SEO url name section, and the URL of the article on my website, all confirmed to be the same of.
Finally, I wanted to roll back the historical version and was surprised to find one thing:
All my blanks, in the current version that cannot be updated, all show
: this is one of the blank symbols, I have done crawler work before, and I am quite curious why the current version automatically converts whitespace to this representation and saves it.
By the way, a few other symbols were converted besides the blanks, and after I rolled back the version, I was able to successfully update the article!
Maybe something went wrong when saving the draft last time. I think some of these representations are against the rules for JSON parsing, so the problem occurs.
You can use the following method to get the source code of your article.
You should see a screen similar to the following:
Copy the section below, then paste it into an online tool that handles escaped characters (like: https://www.freeformatter.com/json-escape.html#ad-output), or use my Python program below to convert:
# coding: utf-8
import html.parser
def main():
# HTMLParser
parser = html.parser.HTMLParser()
# Load data
raw_post = open("post.txt", "r", encoding="utf-8").read()
# Process
new_post = parser.unescape(raw_post)
# Save
with open("new_post.txt", "w", encoding="utf-8") as f:
f.write(new_post)
if __name__ == "__main__":
main()
I first store the part of the original article in the file post.txt, and automatically generate a new file of new_post.txt after conversion. Paste the converted code content from the new file into the WordPress editor and it should now update successfully!
Hope everyone can solve this problem smoothly.