WordPress REST API doesnt work properly with python

I was making a python script that uploads local pdf files to my wordpress website, using the wordpress api, but for some reason, the post method with media endpoint just gives me a lot of random data including other media files instead of uploading my pdf. wp_credentials = f'{wp_user}:{wp_password}' token = base64.b64encode(wp_credentials.encode()) wp_header = { 'Authorization': 'Basic ' + token.decode('utf-8') } def upload_to_wordpress(file_path): media = { 'file': open(file_path, 'rb'), 'caption': f'invoice: {file_path}', 'description': f'invoice: {file_path}' } pdf = requests.post(wp_url, headers=wp_header, files=media) print(pdf) pdf_url = str(json.loads(pdf.content)) print(pdf_url) return pdf_url I tried following the documentation and many other tutorials, but I stumble upon the same problem each time. It also gives me status [200] insetead of the intended [201]. *in the pdf variable i get a list that contains the entire website data: media, products, posts, etc.

Comment (0)

You’ll be in good company