Same Script/Plugin with different results?
#1
Question 
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 failHuh. For some strange reason when I run it through XBMC on the same PC I get a connection reset by peer.


HuhAny 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')>
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
Ok, I found out that when using python 2.4 in windows this problem exists but was obviously fixed in 2.5.

Will XBMC be upgraded to python 2.5 at anytime.
Server: FreeNas 9 NAS: 6*3TB - Kodi Sql Database
Kodi Systems: Nvidia Shield Pro, G-Box Q (OpenElec), RikoMagic MK802 IV[
Skin: reFocus
Reply
#3
Star 
Check out mechanize browser.

I was having trouble with urllib2 and XBMC. However, mechanize works!

PM or post, we need to collaborate on our plugins! A common directory and other features can be added. I am working on this uTorrent plugin.
Reply
#4
f3ar007 Wrote:Check out mechanize browser.

I was having trouble with urllib2 and XBMC. However, mechanize works!

PM or post, we need to collaborate on our plugins! A common directory and other features can be added. I am working on this uTorrent plugin.

Hiya, The problem with this is due to the fact that there does seem to be a problem with version 2.4 of python's http/socket/urllib that has been fixed in Python 2.5. I was looking at this due to the fact I remember from my old utorrent script this didn't work and when creating my torrent site Ive had to copy the url to a file aswell as the torrent to ensure that files are accessible from both ut and az.
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
discussions about it has been brought up, more will be discussed on devcon in the end of june..
Reply
#6
blittan Wrote:discussions about it has been brought up, more will be discussed on devcon in the end of june..

Looking forward to reading the news! Cool
Reply
#7
blittan Wrote:discussions about it has been brought up, more will be discussed on devcon in the end of june..

Thanks Blittan, Ive coded a workaround anyways..
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
Same Script/Plugin with different results?0