id	summary	reporter	owner	description	type	status	priority	component	severity	resolution	keywords	cc	release
10875	wiki.putAttachment fails for larger files	lukasz.matecki@gmail.com	osimons	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 xmlrpcplugin-r12617.zip 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):\r\n{{{\r\nTraceback (most recent call last):\r\n  File "scripts/upload_installer.py", line 9, in <module>\r\n    trac_rpc.upload_attachment(file)\r\n  File "D:\\workspace\\utal\\projects\\pro_plate\\trunk\\scripts\\trac_rpc.py", line 79, in upload_attachment\r\n    server.wiki.putAttachment('InstallersList/{0}'.format(basename), binary)\r\n  File "c:\\Python27\\lib\\xmlrpclib.py", line 1224, in __call__\r\n    return self.__send(self.__name, args)\r\n  File "c:\\Python27\\lib\\xmlrpclib.py", line 1575, in __request\r\n    verbose=self.__verbose\r\n  File "D:\\workspace\\utal\\projects\\pro_plate\\trunk\\scripts\\trac_rpc.py", line 50, in request\r\n    return self._internal_request(host, handler, request_body, verbose)\r\n  File "D:\\workspace\\utal\\projects\\pro_plate\\trunk\\scripts\\trac_rpc.py", line 41, in _internal_request\r\n    f = self._opener.open(request)\r\n  File "c:\\Python27\\lib\\urllib2.py", line 394, in open\r\n    response = self._open(req, data)\r\n  File "c:\\Python27\\lib\\urllib2.py", line 412, in _open\r\n    '_open', req)\r\n  File "c:\\Python27\\lib\\urllib2.py", line 372, in _call_chain\r\n    result = func(*args)\r\n  File "c:\\Python27\\lib\\urllib2.py", line 1207, in https_open\r\n    return self.do_open(httplib.HTTPSConnection, req)\r\n  File "c:\\Python27\\lib\\urllib2.py", line 1174, in do_open\r\n    raise URLError(err)\r\nurllib2.URLError: <urlopen error [Errno 10054] Istniej╣ce po│╣czenie zosta│o gwa│townie zamkniŕte przez zdalnego hosta>\r\nmake: *** [upload] Error 1\r\n}}}\r\n\r\nI'm using the following code to be able to communicate with trac using digest authentication:\r\n{{{\r\n#!python\r\nimport os\r\nimport xmlrpclib\r\nimport httplib\r\nimport urllib2\r\nimport StringIO\r\nimport base64\r\n\r\nclass HTTPSDigestTransport(xmlrpclib.SafeTransport):\r\n    """\r\n    Transport that uses urllib2 so that we can do Digest authentication.\r\n    \r\n    Based upon code at http://bytes.com/topic/python/answers/509382-solution-xml-rpc-over-proxy\r\n    """\r\n\r\n    def __init__(self, username, pw, realm, verbose=None, use_datetime=0):\r\n        self.__username = username\r\n        self.__pw = pw\r\n        self.__realm = realm\r\n        self.verbose = verbose\r\n        self._use_datetime = use_datetime\r\n        self._opener = None\r\n\r\n    def _internal_request(self, host, handler, request_body, verbose):\r\n\r\n        url = 'https://' + host + handler\r\n        if verbose or self.verbose:\r\n            print "ProxyTransport URL: [%s]" % url\r\n            \r\n        request = urllib2.Request(url)\r\n        request.add_data(request_body)\r\n        # Note: 'Host' and 'Content-Length' are added automatically\r\n        request.add_header("User-Agent", self.user_agent)\r\n        request.add_header("Content-Type", "text/xml")  # Important\r\n\r\n        # setup digest authentication\r\n        if self._opener is None:\r\n            authhandler = urllib2.HTTPDigestAuthHandler()\r\n            authhandler.add_password(self.__realm, url, self.__username, self.__pw)\r\n            self._opener = urllib2.build_opener(authhandler)\r\n\r\n        f = self._opener.open(request)\r\n        res = self.parse_response(f)\r\n        f.close()\r\n        return res\r\n\r\n            \r\n    def request(self, host, handler, request_body, verbose):\r\n        for i in (0, 1):        \r\n            try:\r\n                return self._internal_request(host, handler, request_body, verbose)\r\n            except httplib.BadStatusLine:\r\n                if i:\r\n                    raise\r\n                else:\r\n                    print("Restart...")\r\n  \r\ndef get_server():  \r\n    password = raw_input("Enter the repository password: ")\r\n                       \r\n    digestTransport = HTTPSDigestTransport("Lukasz", password, "trac")\r\n    server = xmlrpclib.ServerProxy("....removed....", transport=digestTransport)\r\n\r\n    return server\r\n   \r\ndef upload_attachment(file):\r\n    server = get_server()\r\n    basename = os.path.basename(file)\r\n    print file\r\n    with open(file, "rb") as f:\r\n        data = f.read()\r\n\r\n    print (len(data))\r\n    \r\n    binary = xmlrpclib.Binary(data)\r\n\r\n    print len(binary.data)\r\n\r\n    server.wiki.putAttachment('InstallersList/{0}'.format(basename), binary)\r\n_\r\n# TODO this should be parametrized.\r\nif __name__ == "__main__":\r\n   pass\r\n\r\n}}}\r\n\r\n\r\n\r\n\r\n\r\n	defect	new	normal	XmlRpcPlugin	normal		putAttachment		1.0
