• Resolved Avo

    (@avo)


    Since updating from v3.4.0 to 3.5.1 I’m getting this error when trying to delete a post, using a custom python script. I’ve used this script for the past 16 mths without any issues, until this latest update.

    Error msg:

    Failed to delete post with id 873 on https://xxxxx.com. Status code: 401, Response: {"code":"rest_cannot_delete","message":"Sorry, you are not allowed to delete this post.","data":{"status":401}}

    Reverting to v4.0 the error disappears.

    The puzzling thing is that I can make posts ok with another custom script and it uses the same authentication details I use in my remove_post script.

    Authentication code:

    # Setup the authentication credentials
    username = "xxxxx"
    password = "xxxxxxxxxx"
    token = base64.b64encode(f'{username}:{password}'.encode("utf-8")).decode("utf-8")
    headers = {
        "Authorization": "Basic " + token,
        "Referer": "https://yahoo.com",
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3",
    }

    • This topic was modified 1 month, 1 week ago by Avo.
    • This topic was modified 1 month, 1 week ago by Avo.
    • This topic was modified 1 month, 1 week ago by Avo.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Avo

    (@avo)

    I created a basic delete post script, and it works in v 3.4.0 but fails with 401 error in v 3.5.1

    import requests
    from requests.auth import HTTPBasicAuth

    # Setup the credentials and post information
    username = "xxxxxx"
    app_password = "xxxxxxxxx" # The application password generated in your profile
    post_id = 905 # Replace with the post ID you want to delete
    base_url = "https://xxxxxxxxxx.com" # Replace with your site's base URL

    # Construct the API URL
    api_url = f"{base_url}/wp-json/wp/v2/posts/{post_id}"

    # Send the DELETE request
    response = requests.delete(api_url, auth=HTTPBasicAuth(username, app_password))

    # Check the response
    if response.status_code == 200:
    print(f"Post with ID {post_id} has been successfully deleted.")
    else:
    print(f"Failed to delete post with ID {post_id}. Status code: {response.status_code}, Response: {response.text}")
    Plugin Support yashyadav247

    (@yashyadav247)

    Hi?@avo ,

    Thanks for the patience.

    We just rolled out a new version?3.5.3?that consist of the fix for the issue you had. Now you can delete the post using the Basic Authentication without any issues.

    Just follow the below simple steps to fix the issue on your WP environment –

    • Go to?Protected REST APIs?section.?
    • Click on?Save Settings?and test the API again using the authentication method you have configured.

    Please test and let us know the updates.

    Thanks,
    Team miniOrange

    Thread Starter Avo

    (@avo)

    Thanks for the fix. Just tested on multiple sites and it’s now working.

    cheers, Steve

    Plugin Support abhiladdha07

    (@abhiladdha07)

    Thanks for the update @avo,

    We’re glad that your issue is resolved now. we ‘re marking this thread as closed now. Please feel free to open a new ticket if you have any other questions or face issues. we’d be happy to help.

    Thanks,
    Team miniOrange

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.