[Tutor] Suds, Lxml - sending an xml request

Ismar Sehic i.sheeha at gmail.com
Fri Sep 20 15:25:54 CEST 2013


i'm probably very annoying and boring with these python web service :)and
sorry for the previous message reply subject,wont happen again...
the thing is, i'm provided with some service provider documentation,
including xml request example, xml response example, wsdl file for the
protocol defintion, and xsd file for every request type.
i've played around with LXML and SUDS, and i got this :

xml parsing (i don't really know if i need this, but i made it just to see
how it works ):

try:
>     from lxml import etree
> except ImportError:
>     import xml.etree.ElementTree as etree
> #
> document = etree.parse("HotelValuedAvailRQ.xml")
> root = document.getroot()
>                     #namespaces used
> xmlns = ''
> xsi = '{http://www.hotelbeds.com/schemas/2005/06/messages}'
> #
> user = document.find('//{namespace}User'.format(namespace=namespace))
> user.text = ''      #set hotelbeds user(text)
>
> password =
> document.find('//{namespace}Password'.format(namespace=namespace))
> password.text = ''  #set hotelbeds password(text)
>
> language =
> document.find('//{namespace}Language'.format(namespace=namespace))
> language.text = ''  #set hotelbeds response language(text)
>
>
>                     #set number of pages for xml response(attribute)
> PaginationData = root[2].set('pageNumber', '4')
>                     #set check in date, format :'20130509'
> CheckInDate = root[3].set('date', '')
>                     #set check out date
> CheckOutDate = root[4].set('date', '')
>                     #set dest code, set dest type
> Destination = root[5].set('code', ''); root[5].set('type', '')
>
>                     #set the room count
> RoomCount =
> document.find('//{namespace}RoomCount'.format(namespace=namespace))
> RoomCount.text = ''
>                     #set number of adults
> AdultCount =
> document.find('//{namespace}AdultCount'.format(namespace=namespace))
> RoomCount.text = ''
>                     #set number of children
> ChildCount =
> document.find('//{namespace}ChildCount'.format(namespace=namespace))
> ChildCount.text = '3'
>
> document.write('HotelValuedAvailRQ.xml')
> print '--->Changes saved'
>
>  and i also made this, some suds experiment :

import logging
> logging.basicConfig(level = logging.INFO)
> logging.getLogger('suds.client').setLevel(logging.DEBUG)
> #logging.getLogger('suds.wsdl').setLevel(logging.DEBUG)
> #logging.getLogger('suds.transport').setLevel(logging.DEBUG)
> #logging.getLogger('suds.xsd.schema').setLevel(logging.DEBUG)
> logging.getLogger('suds.wsse').setLevel(logging.DEBUG)
> from suds.client import Client
> url = 'http://xxx.xxx.xxx.xxx/appservices/ws/FrontendService?wsdl'
> client = Client(url)
> print client
>

which gives me following result :

> Suds ( https://fedorahosted.org/suds/ )  version: 0.4 GA  build:
> R699-20100913
>
> Service ( FrontendServiceService ) tns="
> http://www.hotelbeds.com/wsdl/2005/06"
>    Prefixes (0)
>    Ports (1):
>       (FrontendService)
>          Methods (34):
>             cancelProtectionAdd(xs:anyType cancelProtectionAdd, )
>             cancelProtectionRemove(xs:anyType cancelProtectionRemove, )
>             getCancelProtectionAvail(xs:anyType getCancelProtectionAvail, )
>             getCarCountryList(xs:anyType getCarCountryList, )
>             getCarInfoSet(xs:anyType getCarInfoSet, )
>             getCarValuedAvail(xs:anyType getCarValuedAvail, )
>             getCountryList(xs:anyType getCountryList, )
>             getDestinationGroupList(xs:anyType getDestinationGroupList, )
>             getHotelBoardGroupList(xs:anyType getHotelBoardGroupList, )
>             getHotelBoardList(xs:anyType getHotelBoardList, )
>             getHotelCategoryGroupList(xs:anyType
> getHotelCategoryGroupList, )
>             getHotelCategoryList(xs:anyType getHotelCategoryList, )
>             getHotelCountryList(xs:anyType getHotelCountryList, )
>             getHotelDetail(xs:anyType getHotelDetail, )
>             getHotelList(xs:anyType getHotelList, )
>             getHotelRoomTypeGroupList(xs:anyType
> getHotelRoomTypeGroupList, )
>             getHotelValuedAvail(xs:anyType getHotelValuedAvail, )
>             getIncomingOfficeDetail(xs:anyType getIncomingOfficeDetail, )
>             getIncomingOfficeList(xs:anyType getIncomingOfficeList, )
>             getPurchaseDetail(xs:anyType getPurchaseDetail, )
>             getPurchaseList(xs:anyType getPurchaseList, )
>             getTicketAvail(xs:anyType getTicketAvail, )
>             getTicketClassificationList(xs:anyType
> getTicketClassificationList, )
>             getTicketCountryList(xs:anyType getTicketCountryList, )
>             getTicketDetail(xs:anyType getTicketDetail, )
>             getTicketValuation(xs:anyType getTicketValuation, )
>             getTransferCountryList(xs:anyType getTransferCountryList, )
>             getTransferValuedAvail(xs:anyType getTransferValuedAvail, )
>             getZoneGroupList(xs:anyType getZoneGroupList, )
>             purchaseCancel(xs:anyType purchaseCancel, )
>             purchaseConfirm(xs:anyType purchaseConfirm, )
>             purchaseFlush(xs:anyType purchaseFlush, )
>             serviceAdd(xs:anyType serviceAdd, )
>             serviceRemove(xs:anyType serviceRemove, )
>          Types (0):
>
>
can you tell me, what next?i'm reading suds documentation, i have some clue
about the next step, but i'm not sure.do i generate xml request from wsdl
file's methods or do i edit existing xml files provided by the provider,
and send them, and what about xsd files?i'm,interested  only in
getHotelValuedAvail,serviceAdd,serviceRemove,and purchaseFlush methods.

and sorry if the message is too big...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130920/2dc15420/attachment.html>


More information about the Tutor mailing list