classification
Title: SyntaxError in xmlrpc.client examples
Type: compile error Stage:
Components: Documentation Versions: Python 3.0
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: georg.brandl, thijs
Priority: normal Keywords:

Created on 2009-05-21 16:11 by thijs, last changed 2009-05-22 16:44 by georg.brandl. This issue is now closed.

Messages (4)
msg88162 - (view) Author: Thijs Triemstra (thijs) Date: 2009-05-21 16:11
The example is defined as:

import xmlrpc.client

proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")
try:
    proxy.add(2, 5)
except xmlrpc.client.Fault, err:
    print("A fault occurred")
    print("Fault code: %d" % err.faultCode)
    print("Fault string: %s" % err.faultString)

Which throws the following error:

  File "test.py", line 6
    except xmlrpc.client.Fault, err:
                              ^
SyntaxError: invalid syntax

I think it should be defined instead as:

import xmlrpc.client

proxy = xmlrpc.client.ServerProxy("http://localhost:8000/")
try:
    proxy.add(2, 5)
except xmlrpc.client.Fault as err:
    print("A fault occurred")
    print("Fault code: %d" % err.faultCode)
    print("Fault string: %s" % err.faultString)
msg88163 - (view) Author: Thijs Triemstra (thijs) Date: 2009-05-21 17:20
On the same documentation page for Python 3.1b1 it shows a similar error 
for the ProtocolError example:

import xmlrpc.client

# create a ServerProxy with an invalid URI
proxy = xmlrpc.client.ServerProxy("http://invalidaddress/")

try:
    proxy.some_method()
except xmlrpc.client.ProtocolError, err:
    print("A protocol error occurred")
    print("URL: %s" % err.url)
    print("HTTP/HTTPS headers: %s" % err.headers)
    print("Error code: %d" % err.errcode)
    print("Error message: %s" % err.errmsg)

Throws this error:

  File "proto.py", line 8
    except xmlrpc.client.ProtocolError, err:
                                      ^
SyntaxError: invalid syntax

Which should be fixed with:

import xmlrpc.client

# create a ServerProxy with an invalid URI
proxy = xmlrpc.client.ServerProxy("http://invalidaddress/")

try:
    proxy.some_method()
except xmlrpc.client.ProtocolError as err:
    print("A protocol error occurred")
    print("URL: %s" % err.url)
    print("HTTP/HTTPS headers: %s" % err.headers)
    print("Error code: %d" % err.errcode)
    print("Error message: %s" % err.errmsg)
msg88164 - (view) Author: Thijs Triemstra (thijs) Date: 2009-05-21 17:22
Updated ticket title since it's for multiple sections in the 
documentation, not just the Fault example.
msg88200 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-05-22 16:44
Thanks, fixed in r72832.
History
Date User Action Args
2009-05-22 16:44:15georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg88200
2009-05-21 17:22:16thijssetmessages: + msg88164
title: SyntaxError in xmlrpc.client Fault example -> SyntaxError in xmlrpc.client examples
2009-05-21 17:20:20thijssetmessages: + msg88163
2009-05-21 16:11:58thijscreate