Page 1 of 1
[0.5.0Alpha6] addfile in api_handler
Posted: October 15th, 2009, 5:34 pm
by reo
Hello,
The 0.5.0 release got my attention because of the new API possibilities. After implementing the addfile functionality in a third party application I'm working on, it seemed not to be working. I ofcourse thought the problem was within the client application, till later I found the following:
- the HTTP POST message seemed valid (I worked with HTTP a lot more)
- SABnzbd did receive the data properly
- after logging the kwargs, I actually saw the complete nzb-file
In short, in the api_handler method, in the addfile-portion, in interfcae.py, the if statement condition is never met:
Code: Select all
normal_upload = kwargs.get('nzbfile', '')
if normal_upload:
name = normal_upload
When logging the nzbfile argument in kwargs I actually see an instance of the FieldStorage class.
So far my bugreport, I can extend my report with a sample code which will most likely reproduce the bug, if needed. I'm curious to know what the problem might be, as I have absolutely no in-depth knowledge of the SABnzbd project whatsoever, nor I know if it might be a problem in my configuration or anything a like plus I'd love to see it working, ofcourse.
Thanks,
Re: [0.5.0Alpha6] addfile in api_handler
Posted: October 15th, 2009, 6:19 pm
by switch
Could you provide the logging of kwargs you captured, or a sample http request that is sent to sabnzbd. It should contain name="nzbfile" in the content disposition such as in
http://sabnzbd.org/switch/example1.txt
Re: [0.5.0Alpha6] addfile in api_handler
Posted: October 18th, 2009, 4:09 pm
by reo
Yes,
A snippet from interface.py in the api_handler method for the addfile mode:
Code: Select all
normal_upload = kwargs.get('nzbfile', '')
if normal_upload:
name = normal_upload
loggin.debug('It is a FieldStorage..')
logging.debug('What is normal upload \'%s\'', normal_upload)
logging.debug('\n\n')
logging.debug('what is name %s\n\n', name)
logging.debug('kwargs %s', kwargs)
if name != None and name != '' and name.filename and name.value:
sabnzbd.add_nzbfile(name, pp, script, cat, priority, nzbname)
return report(output)
else:
return report(output, _MSG_NO_VALUE)
Code: Select all
2009-10-18 21:44:05,130::DEBUG::[interface:636] What is normal upload 'FieldStorage('nzbfile', 'local.nzb', 'NZB_FILE_CONTENT')'
2009-10-18 21:44:05,167::DEBUG::[interface:638] what is name
2009-10-18 21:44:05,167::DEBUG::[interface:639] kwargs {'ma_password': 'mypassword', 'apikey': 'myapi', 'mode': 'addfile', 'ma_username': 'myusername', 'nzbfile': FieldStorage('nzbfile', 'local.nzb', 'NZB_FILE_CONTENT')}
192.168.1.78 - - [18/Oct/2009:21:44:05] "POST /sabnzbd/api?mode=addfile&apikey=myapi&ma_username=myusername&ma_password=mypassword HTTP/1.1" 200 48 "" "iNZB/1.0 CFNetwork/445.6 Darwin/10.0.0"
As you can seen, the FieldStorage does exist. Perhaps there is a strange boolean operator on the FieldStorage-class which returns false in my case? I have no idea though, again, I have no experience with sabnzbd nor with python.
If I change the condition in the if statement to something like this:
Code: Select all
normal_upload = kwargs.get('nzbfile')
if normal_upload != None and name == '':
name = normal_upload
The adding seems to work just fine.
I hope I have showed enough data to solve this bug.
Re: [0.5.0Alpha6] addfile in api_handler
Posted: November 4th, 2009, 6:03 pm
by reo
Any response? I have had no time to see if it's fixed in the latest SVN, though, it seems not even to be confirmed.
Re: [0.5.0Alpha6] addfile in api_handler
Posted: November 5th, 2009, 2:49 am
by shypike
switch is too busy to do much for SABnzbd.
I'll see if I can track it down.
Re: [0.5.0Alpha6] addfile in api_handler
Posted: November 5th, 2009, 2:24 pm
by reo
Very well, I'd appreciate your help. Let me know if you need additional information.
Re: [0.5.0Alpha6] addfile in api_handler
Posted: November 5th, 2009, 2:49 pm
by shypike
The important info is passed in the "name" argument.
Somehow you also set the "nzbfile" argument, which overrides "name".
The FieldStorage instance is a strange beast, in the sense that you cannot test for "not name".
This is very unusual in Python.
The correct piece of code is this:
Code: Select all
if mode == 'addfile':
# When uploading via flash it will send the nzb in a kw arg called Filedata
if name is None or isinstance(name, str) or isinstance(name, unicode):
name = kwargs.get('Filedata')
# Normal upload will send the nzb in a kw arg called nzbfile
if name is None or isinstance(name, str) or isinstance(name, unicode):
name = kwargs.get('nzbfile')
if name is not None and name.filename and name.value:
sabnzbd.add_nzbfile(name, pp, script, cat, priority, nzbname)
return report(output)
else:
return report(output, _MSG_NO_VALUE)
I have just committed the change.
Re: [0.5.0Alpha6] addfile in api_handler
Posted: November 5th, 2009, 5:42 pm
by reo
Thank you, my project will have great features thanks to this fix. I'll check as soon as I can to verify this issue is resolved.
Have a nice day.