HTTP Posting File Data...
#1
Hi All,

I have this test code below which emulates a form post to transfer a torrent file through to the receiving software which is uTorrent. Now when I run this on from my PC this works flawlessly without a hitch. But when I run it in xbmc python, utorrent reports it as an error although it doesnt tell me the problem. All my other utorrent connectivity from xbmc is fine so I presume that theres some strange but slight difference in the way python runs on xbmc..

If anyone has any ideas on how to solve this it would be appreciated..

Code:
import urllib2
import mimetypes
import mimetools
from    base64      import b64encode
import os

## Create Files Array..
HOME_DIR        =   os.getcwd().replace(";","")+"\\"
# get homedirectory for the script
f       =   open(HOME_DIR + 'dad.torrent','rb')
fdata   =   f.read()
f.close()


BOUNDARY = '----------ThIs_Is_tHe_bouNdaRY_---$---'
CRLF = '\r\n'
L = []
for (key, value) in []:
    L.append('--' + BOUNDARY)
    L.append('Content-Disposition: form-data; name="%s"' % key)
    L.append('')
    L.append(value)
for (key, filename, value) in [['torrent_file','dad.torrent',fdata]]:
    filetype = 'application/x-bittorrent'
    L.append('--' + BOUNDARY)
    L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename))
    L.append('Content-Type: %s' % filetype)
    L.append('')
    L.append(value)
L.append('--' + BOUNDARY + '--')
L.append('')

Body            = CRLF.join(L)
Content         = 'multipart/form-data; boundary=%s' % BOUNDARY

reqst           = urllib2.Request('http://192.168.1.1:5555/gui/?action=add-file',Body)

reqst.add_header('User-Agent','Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3')
reqst.add_header('Content-type',Content)
reqst.add_header('Content-length',str(len(Body)))
reqst.add_header('Authorization','Basic '+ str(b64encode('user:pass')))

try :
    html    =   urllib2.urlopen(reqst)
except Exception,e :
        print str(e)

WebData         = html.read()
html.close()
print str(WebData)
Server: FreeNas 9 NAS: 6*3TB - Kodi Sql Database
Kodi Systems: Nvidia Shield Pro, G-Box Q (OpenElec), RikoMagic MK802 IV[
Skin: reFocus
Reply
#2
What is the error?

I suggest checking the data being sent (Headers and body).

Use some capture tool like Wireshark (formerly ethereal).
42.7% of all statistics are made up on the spot

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#3
Hi utorrent doesnt actually report a specific error only that there was an error. when all other utorrent remote commands work..I have checked the headers and there all there. As far as the body how can i display the binary contents ive tried things like repr etc to print the binary text but i can seem to display it like i can on the pc..

I will have a look at wireshark though..
Server: FreeNas 9 NAS: 6*3TB - Kodi Sql Database
Kodi Systems: Nvidia Shield Pro, G-Box Q (OpenElec), RikoMagic MK802 IV[
Skin: reFocus
Reply
#4
Ive just tested another virtually identicle script i have for Sabnzbd which only opens the file as 'r' as its xml format text and it works flawlessly so i think its something todo with the fact that its binary data..

Downloading wireshark as we speak to hopefully shed some light on this problem.
Server: FreeNas 9 NAS: 6*3TB - Kodi Sql Database
Kodi Systems: Nvidia Shield Pro, G-Box Q (OpenElec), RikoMagic MK802 IV[
Skin: reFocus
Reply
#5
Wireshark cannot monitor windows localhost so i cant compare the raw data being sent. What i cant see is that half way through the transfer i get HTTP 200 response back with the totally unhelpfull utorrent error code. The transfer continues but urllib then reports 'connection reset by peer' which i assume s because it was still trying to send the rest of the file when the HTTP response came back..

Any Ideas..!
Server: FreeNas 9 NAS: 6*3TB - Kodi Sql Database
Kodi Systems: Nvidia Shield Pro, G-Box Q (OpenElec), RikoMagic MK802 IV[
Skin: reFocus
Reply
#6
You are not testing between xbox and pc? Maybe the content-length isn't calculated correctly?

Either way, we should see why utorrent is prematurely sending a 200 back.
42.7% of all statistics are made up on the spot

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#7
The script when run on the PC works exactly as it should it only fails when i run the script on the xbox. What i thought wireshark could do was I could run the script on the pc then on the xbox and then compare the raw data being transmitted..It must be something todo with the binary format as the same script sending txt data to sabnzbd works fine on the xbox..
Server: FreeNas 9 NAS: 6*3TB - Kodi Sql Database
Kodi Systems: Nvidia Shield Pro, G-Box Q (OpenElec), RikoMagic MK802 IV[
Skin: reFocus
Reply
#8
Must be some data that utorrent doesn't like. Utorrent must think the xbox is done sending the data.
42.7% of all statistics are made up on the spot

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
Reply
#9
Thats what im thinkng. I will try today to display the data through the xbox to see exactly what it looks like and try other various formatting options. Im just stabbing in the dark but heres hoping..
Server: FreeNas 9 NAS: 6*3TB - Kodi Sql Database
Kodi Systems: Nvidia Shield Pro, G-Box Q (OpenElec), RikoMagic MK802 IV[
Skin: reFocus
Reply

Logout Mark Read Team Forum Stats Members Help
HTTP Posting File Data...0