API returns HTTP 406 but still continues?

Get help with all aspects of SABnzbd
Forum rules
Help us help you:
  • Are you using the latest stable version of SABnzbd? Downloads page.
  • Tell us what system you run SABnzbd on.
  • Adhere to the forum rules.
  • Do you experience problems during downloading?
    Check your connection in Status and Interface settings window.
    Use Test Server in Config > Servers.
    We will probably ask you to do a test using only basic settings.
  • Do you experience problems during repair or unpacking?
    Enable +Debug logging in the Status and Interface settings window and share the relevant parts of the log here using [ code ] sections.
Post Reply
User avatar
Hmail
Release Testers
Release Testers
Posts: 65
Joined: August 12th, 2008, 1:13 pm

API returns HTTP 406 but still continues?

Post by Hmail »

I'm getting some pretty weird behavior from the API, and I obviously want to talk properly to SABnzbd from my application. I'm sending this data to the api:

Code: Select all

POST /sabnzbd/api?mode=addfile&name=MovieX&cat=anime&apikey=APIKEY HTTP/1.1
Content-Type: multipart/form-data; boundary=8ccafbe245b1ffd
Accept-Encoding: *
Cookie: session_id=18ac5d3efc8874e10940ef97c991a6fc0f879e54
Content-Length: 1856744
Connection: Keep-Alive
Accept-Language: en-US,*
User-Agent: Mozilla/5.0
Host: tiffany:7777

--8ccafbe245b1ffd
Content-Disposition: form-data; name="name"; filename="MovieX"
Content-Type: text/plain

<?xml version="1.0" encoding="iso-8859-1" ?>

// Content stripped from NZB

</nzb>

--8ccafbe245b1ffd--

The API returns a HTML file with error code 406, and I found this in the body:

Code: Select all

        <h2>406 Not Acceptable</h2>
        <p>identity, gzip</p>
I honestly don't know why this is, and I was expecting a 200 OK response. The following header does this, but I don't see much difference:

Code: Select all

POST /sabnzbd/api?mode=addfile&name=MovieX&cat=anime&apikey=APIKEY
HTTP/1.1
Content-Type: multipart/form-data; boundary=8ccb08376f63782
Host: tiffany:7777
Content-Length: 390848
Expect: 100-continue

HTTP/1.1 100
Content-Length: 0
Content-Type: text/plain

--8ccb08376f63782
Content-Disposition: form-data; name="name"; filename="MovieX"
Content-Type: text/plain

<?xml version="1.0" encoding="utf-8" ?>
...
</nzb>


--8ccb08376f63782--

Can someone explain why I get this 406 header, and how to prevent this? Note: SABnzbd still starts the download, like nothing was wrong, but I just want to do it the right way. I got nothing from SABnzbd logs, this just says pretty much the same, that it returned the 406 header.

Also note that the reason these two headers from my application are different is that the first is coded using QT (c++) and the other C#.NET. So different platforms, and I can't get QT to behave exactly like C#.NET.
Last edited by Hmail on April 22nd, 2010, 4:34 pm, edited 1 time in total.
User avatar
switch
Moderator
Moderator
Posts: 1380
Joined: January 17th, 2008, 3:55 pm
Location: UK

Re: API returns HTTP 406 but still continues?

Post by switch »

Looks like an Accept Encoding of "*" might not be supported by CherryPy (our webserver).
http://www.freesoft.org/CIE/RFC/2068/158.htm

If you do not provide an accept encoding at all (as on the second request) it is assumed you can accept all encodings. However * does not seem to be accepted as all encodings.
Last edited by switch on April 22nd, 2010, 6:12 pm, edited 1 time in total.
User avatar
Hmail
Release Testers
Release Testers
Posts: 65
Joined: August 12th, 2008, 1:13 pm

Re: API returns HTTP 406 but still continues?

Post by Hmail »

Is it true it only accepts "Accept-Encoding: gzip" or no Accept-Encoding? Unfortunately, it looks like I can't unset the Accept-Encoding-header, so I either have to live with this, or find a way to gunzip the content. I would love to receive a text/plain response, but I can't request that with the Accept-Encoding header. It keeps returning the 406 error.
Post Reply