New submission from Delaney Gillilan <delaneygilli...@gmail.com>: Documentation available at http://docs.python.org/release/3.0.1/library/xmlrpc.client.html#binary-objects produced incorrect results ...
Traceback (most recent call last): File "test_server.py", line 28, in <module> print(handle.read().format('utf-8')) File "C:\python31\lib\io.py", line 1728, in read decoder.decode(self.buffer.read(), final=True)) File "C:\python31\lib\io.py", line 1299, in decode output = self.decoder.decode(input, final=final) File "C:\python31\lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 252: character maps to <undefined> However a quick change (new to Python3 so this may need work) gives desired results. Server: from xmlrpc.server import SimpleXMLRPCServer import xmlrpc.client def python_logo(): handle = open("python_logo.jpg", "rb") <-- needed "rb" return xmlrpc.client.Binary(handle.read()) handle.close() server = SimpleXMLRPCServer(("localhost", 8000)) print("Listening on port 8000...") server.register_function(python_logo, 'python_logo') server.serve_forever() Client: import xmlrpc.client proxy = xmlrpc.client.ServerProxy("http://localhost:8000/") handle = open("fetched_python_logo.jpg", "wb") <-- needed "wb" handle.write(proxy.python_logo().data) handle.close() Please update the documentation. Thanks! ---------- components: Library (Lib) messages: 109021 nosy: Delaney.Gillilan priority: normal severity: normal status: open title: XMLRPC documentation binary file example does not execute. type: crash versions: Python 3.1 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue9135> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com