16h00 - Fil rouge « Client Sympa SOAP »

Navigation rapide : Lundi / Mardi / Mercredi / Jeudi / Vendredi Mémos : Perl / Python / Ruby

Enoncé

A l'aide du client Sympa SOAP fourni, ajouter le code nécessaire pour

  1. lister les listes disponibles
    • utiliser l'appel SOAP à la fonction Sympa « complex_list »
  2. lister les abonnés d'une liste
    • utiliser l'appel SOAP à la fonction Sympa « review »

client soap

 1: """Acces à SOAP"""
 2:
 3: import suds
 4: from suds.client import Client
 5: from suds.xsd.doctor import Import, ImportDoctor
 6: import cookielib
 7: import logging
 8:
 9: import sys
10: import getopt
11:
12: logging.basicConfig(level=logging.INFO)
13: logging.getLogger('suds.client').setLevel(logging.CRITICAL)
14: tns="https://listes.example.com/sympa/wsdl"
15: url="https://listes.example.com/sympasoap"
16:
17: imp = Import('http://schemas.xmlsoap.org/soap/encoding/')
18: imp.filter.add(tns)
19: doctor = ImportDoctor(imp)
20: client = Client(tns, doctor=doctor, location=url)
21:
22: # à compléter

Corrigé

python

 1: """Acces à SOAP"""
 2:
 3: import suds
 4: from suds.client import Client
 5: from suds.xsd.doctor import Import, ImportDoctor
 6: import cookielib
 7: import logging
 8:
 9: import sys
10: import getopt
11:
12: logging.basicConfig(level=logging.INFO)
13: logging.getLogger('suds.client').setLevel(logging.CRITICAL)
14: tns="https://listes.example.com/sympa/wsdl"
15: url="https://listes.example.com/sympasoap"
16:
17: imp = Import('http://schemas.xmlsoap.org/soap/encoding/')
18: imp.filter.add(tns)
19: doctor = ImportDoctor(imp)
20: client = Client(tns, doctor=doctor, location=url)
21: print repr(client)
22:
23: sympa_cookie = '58828728051313'
24: try:
25:         opt,args = getopt.getopt(sys.argv[1:], "hc:", ["help","cookie="])
26: except getopt.GetoptError,err:
27:         print str(err)
28:         sys.exit(2)
29:
30: for option in opt:
31:         if option[0]=='-h' or option[0]=="--help":
32:                 print __doc__
33:                 sys.exit(1)
34:     if option[0]=='-c' or option[0]=="--cookie":
35:         sympa_cookie=option[1]
36:
37: cookie = cookielib.Cookie(
38:     version=0,
39:     name="sympa_session",
40:     value=sympa_cookie,
41:     port=None, port_specified=False,
42:     domain="listes.example.com", domain_specified=False, domain_initial_dot=False,
43:     path="/", path_specified=True,
44:     secure=True, expires=None,
45:     discard=True,
46:     comment=None, comment_url=None, rest={'HttpOnly': None})
47: client.options.transport.cookiejar.set_cookie(cookie)
48:
49: print repr(cookie)
50:
51: print "cookie"
52: print client.service.checkCookie()
53:
54: print "listes"
55: print client.service.lists()
56: print client.service.complexLists()
57: print client.service.which()
58: print client.service.complexWhich()
59: print client.service.subscribe("anf2012@example.com")
60:
61:
62: try:
63:     print client.service.review("anf2012@example.com")
64: except suds.WebFault as fault:
65:     print fault.fault.faultstring
66:         print fault.fault.detail
jeudi_corrige_python_3.txt · Last modified: 2012/05/24 14:41 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki