Ecommerce Shopify WordPress Discussion

Trying to publish blog posts via the Rest API on a WordPress Blog that is installed on a Hostgator website. It's being blocked by Mod_Security

Here is the Python script I'm using: import requests from requests.auth import HTTPBasicAuth url = 'https://my-phenomenal-website.com/blog/wp-json/wp/v2/posts' data = { 'title': 'TEST POST 1.1', 'content': 'My outstanding content would go RIGHT HERE', 'status': 'publish' } # Replace 'your_username' with the WordPress username # Replace 'your_application_password' with the application password you created auth = HTTPBasicAuth('USERNAME IS HERE', 'PASSWORD GOES HERE') response = requests.post(url, json=data, auth=auth) if response.status_code == 201: print("Post published successfully.") else: print("Failed to publish post:", response.content) tried both the admin username, as well as another username, using the Application Password I created for each user. No luck. Response is as follows: Failed to publish post: b'<head><title>Not Acceptable!</title></head><body><h1>Not Acceptable!</h1><p>An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security.</p></body></html>' Tried modifying the .htaccess file, both on the root domain, as well as the /blog subdomain, to disable mod security, as many recommend to fix this. No luck. Still getting the same error. <IfModule mod_security.c> SecFilterEngine Off SecFilterScanPOST Off </IfModule> Other ideas for how I could resolve this issue?
I spent HOURS trying to resolve this issue, and here is what worked for me: import requests import json # Import for json.dumps ROOT = 'https://your-website.com/blog/' AUTH_USER = 'Your Wordpress Username' AUTH_PASSWORD = 'Your password, created using the Application Passwords section under the above user in the Wordpress Users section' headers = { 'Content-Type': 'application/json', 'User-Agent': 'My Python WordPress API Script' # Anything will work here apparently, just important that BOTH of these are included. } data = { 'title': 'Test WP API', 'status': 'publish', 'slug': 'test-wp-api', 'author': 1, 'content': 'This is my first post created using REST-API' # include ALL of these parameters for it to work properly } # Convert data to JSON format data_json = json.dumps(data) response = requests.post(url=ROOT + 'wp-json/wp/v2/posts', data=data_json, headers=headers, auth=(AUTH_USER, AUTH_PASSWORD)) if response.status_code == 201: print("Post published successfully.") else: print("Failed to publish post:", response.content)

January 7, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.