This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: XMLRPC documentation binary file example does not execute.
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Delaney.Gillilan, ezio.melotti
Priority: normal Keywords:

Created on 2010-06-30 21:57 by Delaney.Gillilan, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (2)
msg109021 - (view) Author: Delaney Gillilan (Delaney.Gillilan) Date: 2010-06-30 21:57
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!
msg109022 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2010-06-30 21:59
This is already fixed in the latest version of the doc: http://docs.python.org/py3k/library/xmlrpc.client.html#binary-objects
History
Date User Action Args
2022-04-11 14:57:03adminsetgithub: 53381
2010-06-30 21:59:29ezio.melottisetstatus: open -> closed

type: crash -> behavior

nosy: + ezio.melotti
messages: + msg109022
resolution: out of date
stage: resolved
2010-06-30 21:57:16Delaney.Gillilancreate