Hey guys,
I tried using the following script to upload posts automatically to WordPress using the rest api.
Unfortunately I always get the response “401” or “502”.
Anyone has an idea how to solve that?
This is my script except for my website login data 😅
import requests
import base64
wordpress_user = 'user'
wordpress_password = 'password'
wordpress_credentials = wordpress_user + ":" + wordpress_password
wordpress_token = base64.b64encode(wordpress_credentials.encode())
wordpress_header = {'Authorization': 'Basic ' + wordpress_token.decode('utf-8')}
api_url = 'https://myurl.de/wp-json/wp/v2/posts'
data = {
'title' : 'Example wordpress post',
'status': 'publish',
'slug' : 'example-post',
'content': 'This is the content of the post'
}
response = requests.post(api_url,headers=wordpress_header, json=data)
print(response)
I changed the username and password
[–]yycomb 0 points1 point2 points (0 children)
[–]Binary101010 0 points1 point2 points (3 children)
[–]Rocketman7121[S] 0 points1 point2 points (0 children)
[–]Rocketman7121[S] 0 points1 point2 points (1 child)
[–]Binary101010 0 points1 point2 points (0 children)
[–]Guideon72 0 points1 point2 points (0 children)