[New-bugs-announce] [issue9135] XMLRPC documentation binary file example does not execute.

Delaney Gillilan report at bugs.python.org
Wed Jun 30 23:57:19 CEST 2010

New submission from Delaney Gillilan <delaneygillilan at 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>
  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.

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())
server = SimpleXMLRPCServer(("localhost", 8000))
print("Listening on port 8000...")
server.register_function(python_logo, 'python_logo')

import xmlrpc.client
proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")
handle = open("fetched_python_logo.jpg", "wb") <-- needed "wb"

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 <report at bugs.python.org>

More information about the New-bugs-announce mailing list