import requests
import os
from requests.auth import HTTPBasicAuth
def upload_image(image_path):
api_url = 'https://example.com/jsonapi/node/event/a8ef729b-1fd6-4233-979a-fa0f81132dde/field_image' #?_format=json
auth = HTTPBasicAuth('Username', 'Password')
image_filename = os.path.basename(image_path)
headers = {'Content-Type': 'application/octet-stream',
'Content-Disposition': 'file; filename="{}"'.format(image_filename.replace('images/', ''))}
multipart_form_data = {'file': (image_filename, open(image_path, 'rb'))}
print(api_url)
print(auth)
print(image_filename)
print(headers)
response = requests.post(api_url, files=multipart_form_data, headers=headers, auth=auth)
print(response.json())
return None
upload_image('images/test.jpg')