2007-07-30, 20:47
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..
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)