I am trying to have a custom GPT connect to my wordpress website and publish a new post. I have verified the schema I created works for
- connecting and authenticating to the api
- correctly submitting the article title, content, slugs, etc
- correctly uploading an image to the correct endpoint
Each time I run the GPT and get to the step where it uploads the image to the correct location on wordpress I get an error that the username/password was incorrect. Running a curl command locally shows the username and application password is actually correct.
I hardcoded the wordpress URL, username, and application password to a file that I uploaded to the GPT so I can be sure. I then asked it to try again while outputting the full analysis of its attempt. The following is the simple auth script it is executing with the username , url, and password omitted:
import requests
import base64
import json
# Load the authentication details from the 'auth_wordpress.py' file.
# For security reasons, the content of this file is not displayed or accessible directly.
# Instead, we use the provided information to authenticate and interact with the WordPress API.
# Assuming 'auth_wordpress.py' contains the necessary credentials and URL for the WordPress site
wordpress_url = [omitted]
app_username = [omitted]
app_password = [omitted]
# Encode the credentials using Base64
credentials = f"{app_username}:{app_password}"
token = base64.b64encode(credentials.encode())
header = {'Authorization': f'Basic {token.decode()}'}
# Prepare the image file for upload
image_filename = 'C:\\Users\\me\\Downloads\\855af5.jpg'
image_data = open(image_filename, 'rb').read()
# Construct the request for media upload
media_url = f"{wordpress_url}/wp/v2/media"
media_headers = {
'Authorization': header['Authorization'],
'Content-Disposition': 'attachment; filename="855af5.jpg"',
'Content-Type': 'image/png',
}
response = requests.post(media_url, headers=media_headers, data=image_data)
# Check the response status and handle accordingly
if response.status_code == 201:
image_id = response.json()['id']
print("Image uploaded successfully. Image ID:", image_id)
else:
print("Failed to upload image. Status Code:", response.status_code, "Response:", response.text)
This gave me a network resolution error from the GPT; however, running this script locally with the values hardcoded resulted in the image successfully uploading. Is wordpress blocking the GPT connection to the API? What could possibly be causing this issue?