[Tutor] Suds, Lxml - sending an xml request

2013-09-23 Thread Ismar Sehic
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, )
 

Re: [Tutor] Suds, Lxml - sending an xml request

2013-09-23 Thread Walter Prins
Hi,


On 20 September 2013 14:25, Ismar Sehic i.she...@gmail.com wrote:

 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.


You should not need to mess with lxml yourself if you're using a SOAP
library like suds.   Also, you might try SOAPpy, or alternatively, try ZSI
if you can get it working -- the project seems kind of dead and not
recently updated and I seem to remember it was rather fiddly to get it
working last time I had to work with it.  (That said I might add that we've
had good success with ZSI.  Usefully, it can generate wrapper classes for
your WSDL which means you get a concrete native Python representation that
you can refer to, of the webservice interface you're trying to work with.
 SOAPpy and other more recent frameworks takes a more minimalist approach
and does everything dynamically which can sometimes make it a bit tricky to
work with a new interface.)

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor