Can’t upload image on wordpress with python api
-
This is my python function to save images and upload them on my website
def uploadImage(image_url, sku): url='https://website.com/wp-json/wp/v2/media' user_agent = UserAgent().random headers = {"User-Agent": user_agent} #Image download img_data = requests.get(image_url, headers=headers).content with open(f'{sku}.jpg', 'wb') as handler: handler.write(img_data) media = {'file': open(f'{sku}.jpg',"rb")} user = "user" password = "XXXX XXXX XXXX XXXX XXXX XXXX" credentials = user + ':' + password token = base64.b64encode(credentials.encode()) res = requests.post(url= url, headers={ 'Authorization': 'Basic ' + token.decode('utf-8')}, files= media, ) print(res)
For the auth I use Application Passwords plugin
res
?is 200 and if I print?res.json()
?it returns a list of the images I have on my website, but the image is not uploaded, there is no error in the response or the image filename.Tried with different users and also disabling all plugins, but nothing changed. Tried also with auth with username and password and had the same problem
Current version: 6.1.1
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Can’t upload image on wordpress with python api’ is closed to new replies.