API error "Unsupported Media Type"


#1

Using Python, I’m unable to successfully upload an image to the API. Is there sample Python code, or can someone advise on how to prepare the post request?


#2

Did you read through this guide? https://developer.deeparteffects.com/page/guide
Please pay attention to convert the image to base64


#3

Hi, I did read the guide, and I have been converting the image. If the request is properly formatted, the return is always

{
“message”: “Unsupported Media Type”
`

Using the sample JS code on github, this is the request that is created: https://pastebin.com/ysuDcGQV

Please let me know what I’m doing wrong.


#4

What image type did you use?


#5

I used a jpg with a max dimension of 1080px.


#6

still need help on this please


#7

bump. please, i would like to pay for this service, but i can’t even get the test plan to work.


#8

We will send you some sample python code.


#9

Thank you.

Here is the code I’m using now: https://gist.github.com/alexruimy/0bad1f51f2be0c8aca0f193d18b2deab


#10

import base64
import requests
import json
from PIL import Image

API_KEY = ‘INSERT-API-KEY’
UPLOAD_URL = ‘https://api.deeparteffects.com/v1/noauth/upload
STYLES_URL = ‘https://api.deeparteffects.com/v1/noauth/styles
RESULT_URL = ‘https://api.deeparteffects.com/v1/noauth/result?submissionId=%s
HEADERS = {‘content-type’: ‘application/json’, ‘x-api-key’: API_KEY}

def encode_image(image_file):
with open(image_file, “rb”) as f:
str = base64.b64encode(f.read()).decode()
return str

def upload_image(image_file, style_id, original_colors=False):

data = {
    "styleId": style_id,
    "imageBase64Encoded": encode_image(image_file)
}

r = requests.post(UPLOAD_URL, data=json.dumps(data), headers=HEADERS)
print(r.status_code, r.reason)

upload_image(‘image.jpg’, ‘c7984d3c-1560-11e7-afe2-06d95fe194ed’)


#11

Thank you, this works!