Opened 5 years ago

Last modified 5 years ago

#10875 new defect

wiki.putAttachment fails for larger files

Reported by: lukasz.matecki@… Owned by: osimons
Priority: normal Component: XmlRpcPlugin
Severity: normal Keywords: putAttachment
Cc: Trac Release: 1.0


I'm using Trac 1.0 over stunnel (tracd, https). The attachment maximum size for the environment is set to 2 MB. I've downloaded the most recent and installed it. When I'm sending a (binary) file that is 50 kB everything seems to be OK. When I try to send larger file (>100 kB) I get the following error (the file contains binary data):

Traceback (most recent call last):
  File "scripts/", line 9, in <module>
  File "D:\workspace\utal\projects\pro_plate\trunk\scripts\", line 79, in upload_attachment'InstallersList/{0}'.format(basename), binary)
  File "c:\Python27\lib\", line 1224, in __call__
    return self.__send(self.__name, args)
  File "c:\Python27\lib\", line 1575, in __request
  File "D:\workspace\utal\projects\pro_plate\trunk\scripts\", line 50, in request
    return self._internal_request(host, handler, request_body, verbose)
  File "D:\workspace\utal\projects\pro_plate\trunk\scripts\", line 41, in _internal_request
    f =
  File "c:\Python27\lib\", line 394, in open
    response = self._open(req, data)
  File "c:\Python27\lib\", line 412, in _open
    '_open', req)
  File "c:\Python27\lib\", line 372, in _call_chain
    result = func(*args)
  File "c:\Python27\lib\", line 1207, in https_open
    return self.do_open(httplib.HTTPSConnection, req)
  File "c:\Python27\lib\", line 1174, in do_open
    raise URLError(err)
urllib2.URLError: <urlopen error [Errno 10054] Istniej╣ce po│╣czenie zosta│o gwa│townie zamkniŕte przez zdalnego hosta>
make: *** [upload] Error 1

I'm using the following code to be able to communicate with trac using digest authentication:

import os
import xmlrpclib
import httplib
import urllib2
import StringIO
import base64

class HTTPSDigestTransport(xmlrpclib.SafeTransport):
    Transport that uses urllib2 so that we can do Digest authentication.
    Based upon code at

    def __init__(self, username, pw, realm, verbose=None, use_datetime=0):
        self.__username = username
        self.__pw = pw
        self.__realm = realm
        self.verbose = verbose
        self._use_datetime = use_datetime
        self._opener = None

    def _internal_request(self, host, handler, request_body, verbose):

        url = 'https://' + host + handler
        if verbose or self.verbose:
            print "ProxyTransport URL: [%s]" % url
        request = urllib2.Request(url)
        # Note: 'Host' and 'Content-Length' are added automatically
        request.add_header("User-Agent", self.user_agent)
        request.add_header("Content-Type", "text/xml")  # Important

        # setup digest authentication
        if self._opener is None:
            authhandler = urllib2.HTTPDigestAuthHandler()
            authhandler.add_password(self.__realm, url, self.__username, self.__pw)
            self._opener = urllib2.build_opener(authhandler)

        f =
        res = self.parse_response(f)
        return res

    def request(self, host, handler, request_body, verbose):
        for i in (0, 1):        
                return self._internal_request(host, handler, request_body, verbose)
            except httplib.BadStatusLine:
                if i:
def get_server():  
    password = raw_input("Enter the repository password: ")
    digestTransport = HTTPSDigestTransport("Lukasz", password, "trac")
    server = xmlrpclib.ServerProxy("....removed....", transport=digestTransport)

    return server
def upload_attachment(file):
    server = get_server()
    basename = os.path.basename(file)
    print file
    with open(file, "rb") as f:
        data =

    print (len(data))
    binary = xmlrpclib.Binary(data)

    print len('InstallersList/{0}'.format(basename), binary)
# TODO this should be parametrized.
if __name__ == "__main__":

Attachments (0)

Change History (1)

comment:1 Changed 5 years ago by lukasz.matecki@…

Keywords: putAttachment added

Modify Ticket

Change Properties
Set your email in Preferences
as new The owner will remain osimons.

Add Comment

E-mail address and name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.