2009-06-07, 00:41
Hi,
I have a test script for uploading files into uTorrent via a multipart/form-data. The strange thing is is that the script when run through python on PC this works without fail. For some strange reason when I run it through XBMC on the same PC I get a connection reset by peer.
Any help would be much appreciated..
and heres the error log:
I have a test script for uploading files into uTorrent via a multipart/form-data. The strange thing is is that the script when run through python on PC this works without fail. For some strange reason when I run it through XBMC on the same PC I get a connection reset by peer.
Any help would be much appreciated..
Code:
# -*- coding: utf-8 -*-
import urllib,urllib2,re,os,string,types,time
from base64 import b64encode
from types import *
## DEFAULTPATH
MyPath = os.getcwd()
MyTorrents = MyPath +'\\'
MyMedia = MyPath +'\\media'
URL ='http://192.168.1.64:9001/gui/'
USER='username'
PASS='password'
def HttpCmd(urldta,postdta=None,content=None):
print '--HttpCmd--'
print urldta
## Standard code
header = {'Authorization':'Basic '+ str(b64encode(USER+":"+PASS))}
req = urllib2.Request(urldta,postdta,headers=header)
req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
## Process only if Upload..
if content != None :
req.add_header('Content-Type',content)
req.add_header('Content-Length',str(len(postdta)))
print '--REQUEST--'
print str(req.headers)
response = urllib2.urlopen(req)
print str(response)
link=response.read()
print str(link)
response.close()
return link
def SendTorrent(TorrentFile) :
## Read file data..
realfile = MyTorrents + TorrentFile
print str(realfile)
f = open(realfile,'rb')
fdata = f.read()
f.close()
## Create post data..
print 'Pre Post-Data is :' + str(len(fdata)) +' Bytes'
Contentx,Postx = MultiPart([],[['torrent_file',TorrentFile,fdata]],'torrent')
if Contentx == None and Postx == None : raise Exception
print str(Contentx)
print 'Post Post-Data is :' + str(len(Postx)) +' Bytes'
f=open(MyPath + '\\test.txt','wb')
for i in Postx :
f.write(i)
f.close()
## Now Action the command..?action=add-file
Response = HttpCmd('http://192.168.1.66:9001/gui/'+'?action=add-file',postdta=Postx,content=Contentx)
print str(Response)
if Response == None : raise Exception
else : return True
def MultiPart(fields,files,ftype) :
Boundary = '----------ThIs_Is_tHe_bouNdaRY_---$---'
CrLf = '\r\n'
L = []
## Process the Fields required..
for (key, value) in fields :
L.append('--' + Boundary)
L.append('Content-Disposition: form-data; name="%s"' % key)
L.append('')
L.append(value)
## Process the Files..
for (key, filename, value) in files :
L.append('--' + Boundary)
L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (key, filename))
## Set filetype based on .torrent or .nzb files.
if ftype == 'torrent' : filetype = 'application/x-bittorrent'
else : filetype = 'text/xml'
L.append('Content-Type: %s' % filetype)
## Now add the actual Files Data
L.append('')
L.append(value)
## Add End of data..
L.append('--' + Boundary + '--')
L.append('')
## Heres the Main stuff that we will be passing back..
post = CrLf.join(L)
content_type = 'multipart/form-data; boundary=%s' % Boundary
## Return the formatted data..
return content_type, post
SendTorrent('Test.torrent')
and heres the error log:
Code:
23:23:28 T:3072 M:371720192 NOTICE: http://192.168.1.66:9001/gui/?action=add-file
23:23:28 T:3072 M:371720192 NOTICE:
23:23:28 T:3072 M:371699712 NOTICE: --REQUEST--
23:23:28 T:3072 M:371699712 NOTICE:
23:23:28 T:3072 M:371699712 NOTICE: {'Content-length': '28590', 'Content-type': 'multipart/form-data; boundary=----------ThIs_Is_tHe_bouNdaRY_---$---', 'Authorization': 'Basic Y2h1bmsxOTcwOmNhcmx0b24yNg==', 'User-agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3'}
23:23:28 T:3072 M:371699712 NOTICE:
23:23:28 T:3072 M:371650560 NOTICE: Traceback (most recent call last):
23:23:28 T:3072 M:371650560 NOTICE: File "C:\Documents and Settings\Chunk\Application Data\XBMC\plugins\programs\Test\default.py", line 103, in ?
23:23:28 T:3072 M:371638272 NOTICE:
23:23:28 T:3072 M:371638272 NOTICE: SendTorrent('Test.torrent')
23:23:28 T:3072 M:371638272 NOTICE: File "C:\Documents and Settings\Chunk\Application Data\XBMC\plugins\programs\Test\default.py", line 59, in SendTorrent
23:23:28 T:3072 M:371638272 NOTICE:
23:23:28 T:3072 M:371638272 NOTICE: Response = HttpCmd('http://192.168.1.66:9001/gui/'+'?action=add-file',postdta=Postx,content=Contentx)
23:23:28 T:3072 M:371638272 NOTICE: File "C:\Documents and Settings\Chunk\Application Data\XBMC\plugins\programs\Test\default.py", line 31, in HttpCmd
23:23:28 T:3072 M:371638272 NOTICE:
23:23:28 T:3072 M:371638272 NOTICE: response = urllib2.urlopen(req)
23:23:28 T:3072 M:371638272 NOTICE: File "special:\\xbmc\system\python\python24.zlib\urllib2.py", line 130, in urlopen
23:23:28 T:3072 M:371638272 NOTICE: File "special:\\xbmc\system\python\python24.zlib\urllib2.py", line 358, in open
23:23:28 T:3072 M:371638272 NOTICE: File "special:\\xbmc\system\python\python24.zlib\urllib2.py", line 376, in _open
23:23:28 T:3072 M:371638272 NOTICE: File "special:\\xbmc\system\python\python24.zlib\urllib2.py", line 337, in _call_chain
23:23:28 T:3072 M:371638272 NOTICE: File "special:\\xbmc\system\python\python24.zlib\urllib2.py", line 1021, in http_open
23:23:28 T:3072 M:371638272 NOTICE: File "special:\\xbmc\system\python\python24.zlib\urllib2.py", line 996, in do_open
23:23:28 T:3072 M:371638272 NOTICE: urllib2
23:23:28 T:3072 M:371638272 NOTICE: .
23:23:28 T:3072 M:371638272 NOTICE: URLError
23:23:28 T:3072 M:371638272 NOTICE: :
23:23:28 T:3072 M:371638272 NOTICE: <urlopen error (10054, 'Connection reset by peer')>