Error 406 with API photos_profile_add

Deg Un Posted in Technical Support 3 weeks ago

Hello,
I am trying to add user profile picture with API in Python with this code :

image_path = download_image(user['picture.large'])
                with open(image_path, 'rb') as img:
                    files = {'userphoto[]': (os.path.basename(image_path), img, 'image/jpeg')}
                    url = f"{OSSN_URL}/api/v1.0/photos_profile_add?api_key_token={OSSN_API_KEY}&guid={guid}"
                    photo_response = requests.post(url, files=files)
                    print("Photo Upload Response:", photo_response.text)

                    os.remove(image_path)

But everytime I get this message :

Photo Upload Response: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>406 Not Acceptable</title>
</head><body>
<h1>Not Acceptable</h1>
<p>An appropriate representation of the requested resource could not be found on this server.</p>
<p>Additionally, a 406 Not Acceptable
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>

I also tried with a CURL command, with the same issue…

Replies
French Deg Un Replied 3 weeks ago

It's working thanks a lot !

Indonesian Arsalan Shah Replied 3 weeks ago

Because its single photo you seens sending array userphoto[] should be only userphoto i guess

French Deg Un Replied 3 weeks ago

Thanks !
I disabled Modsecurity for the test.
But now I have a different error with the payload :

 "message": "ossnservices:cannotaddalbum:photo"

It is strange, because I used to install OSSN without problem with the same script and it worked…

Indonesian Arsalan Shah Replied 3 weeks ago

Maybe your provider mod security blocking this request. You can ask them to disable mod security for your website.

Alternatively try localhost ossn installation and see if it works or not.