Hello,

Below is my code:

#!/bin/env python
# -*- coding: utf-8 -*-
import requests
from lxml import etree

url = 'http://192.168.0.1/webservice.svc?wsdl'
headers = {'Content-Type': 'text/xml;charset=UTF-8', 'SOAPAction': '
http://tempuri.org/ITService/SignIn'}
xml = '''<soapenv:Envelope xmlns:soapenv="
http://schemas.xmlsoap.org/soap/envelope/"; xmlns:tem="http://tempuri.org/";>
            <soapenv:Header></soapenv:Header>
            <soapenv:Body>
                <tem:SignIn>
                    <tem:rq>
                        <env:ClientSystem>123</env:ClientSystem>
                        <env:CompanyId>123</env:CompanyId>
                        <env:Password>123</env:Password>
                        <env:Signature>omg</env:Signature>
                    </tem:rq>
                </tem:SignIn>
            </soapenv:Body>
        </soapenv:Envelope>'''

response = requests.post(url, data=xml, headers=headers).text
print response

doc = etree.parse(response)


The content of variable response is a big XML with some values that I want.

Part of variable response:
---------------------------------------------------------------------------------------------------------------------
<s:Envelope 
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/";><s:Body><SignInResponse
xmlns="http://tempuri.org/";><SignInResult xmlns:a="
http://schemas.datacontract.org/2004/07/Core.DTO.Envelopes.Authentication";
xmlns:i="http://www.w3.org/2001/XMLSchema-instance";><Errors xmlns="
http://schemas.datacontract.org/2004/07/Framework.BaseEnvelopes"; xmlns:b="
http://schemas.datacontract.org/2004/07/Framework"/><Messages xmlns="
http://schemas.datacontract.org/2004/07/Framework.BaseEnvelopes"; xmlns:b="
http://schemas.datacontract.org/2004/07/Framework"/><Successful xmlns="
http://schemas.datacontract.org/2004/07/Framework.BaseEnvelopes";>true</Successful><Warnings
xmlns="http://schemas.datacontract.org/2004/07/Framework.BaseEnvelopes";
xmlns:b="http://schemas.datacontract.org/2004/07/Framework"/><a:ApplicationSettings
xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays
"><b:KeyValueOfstringstring><b:Key>removeDuplicatedFlights</b:Key><b:Value>true</b:Value></b:KeyValueOfstringstring><b:KeyValueOfstringstring><b:Key>useWeakPassword</b:Key>
---------------------------------------------------------------------------------------------------------------------

Below the return of doc = etree.parse(response)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 3630:
ordinal not in range(128)
The type of response is unicode.


The whole idea is sign in on this webservice and get a Security token and
then run another XML on the same script.

Any ideas to transform this unicode on XML and parse it?

Best Regards,

Danilo
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to