Created
February 4, 2016 00:23
-
-
Save netoxico/e105d7d8b22a5d2b9de9 to your computer and use it in GitHub Desktop.
xml2json.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding: utf-8 | |
import xmltodict | |
from xmltodict import unparse | |
XML = """ | |
<SOAP-ENV:Envelope xmlns:tns="http://MMIT.Gateway.WebServices" xmlns:ns0="http://schemas.multi-mit.com/DataFormat" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns2="http://MMIT.Gateway.WebServices" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> | |
<SOAP-ENV:Header> | |
<tns:UserAccessTokenHeader> | |
<tns:GUID>36e943fc-c5b8-4c84-a847-68946ebe93c5</tns:GUID> | |
</tns:UserAccessTokenHeader> | |
</SOAP-ENV:Header> | |
<ns1:Body> | |
<ns2:SendMessage> | |
<ns2:request> | |
<ns2:MMIT_DataRecord> | |
<ns0:Supplier_Code>Interalia</ns0:Supplier_Code> | |
<ns0:Country_Code>MX</ns0:Country_Code> | |
<ns0:Market_Code>GMMX</ns0:Market_Code> | |
<ns0:Source_Code>MEX_04_INTERNET_HR_LEADIT</ns0:Source_Code> | |
<ns0:Source>HR</ns0:Source> | |
<ns0:Person_Data> | |
<ns0:First_Names Order="1">agencia </ns0:First_Names> | |
<ns0:Last_Names Order="1">prueba</ns0:Last_Names> | |
<ns0:Gender>U</ns0:Gender> | |
</ns0:Person_Data> | |
<ns0:Company_Data> | |
<ns0:Company_Name>MCCANN-ERICKSON DE MEXICO SA DE CV</ns0:Company_Name> | |
</ns0:Company_Data> | |
<ns0:Address/> | |
<ns0:Communication> | |
<ns0:Email>[email protected]</ns0:Email> | |
<ns0:Telephone>5555555555</ns0:Telephone> | |
<ns0:Preferred_Channel>EMAIL</ns0:Preferred_Channel> | |
</ns0:Communication> | |
<ns0:Associated_Dealer_Data> | |
<ns0:Dealer Code="812516342" Type="PREF"/> | |
</ns0:Associated_Dealer_Data> | |
<ns0:Contact_Data> | |
<ns0:Action_Id>25</ns0:Action_Id> | |
<ns0:Content Type="QUEST_4DEALER"> | |
<ns0:Fulfillment_Data> | |
<ns0:Campaign_Code>MX_P RECAL_MERC</ns0:Campaign_Code> | |
</ns0:Fulfillment_Data> | |
</ns0:Content> | |
<ns0:Medium>INTER</ns0:Medium> | |
<ns0:Status>I</ns0:Status> | |
<ns0:Date>20141112</ns0:Date> | |
</ns0:Contact_Data> | |
<ns0:Suppression_Data> | |
<ns0:Global_Opt_In> | |
<ns0:Channel NAME="SMS">YES</ns0:Channel> | |
<ns0:Channel NAME="EMAIL">YES</ns0:Channel> | |
</ns0:Global_Opt_In> | |
</ns0:Suppression_Data> | |
</ns2:MMIT_DataRecord> | |
</ns2:request> | |
</ns2:SendMessage> | |
</ns1:Body> | |
</SOAP-ENV:Envelope> | |
""" | |
def main(): | |
doc = xmltodict.parse(XML) | |
print doc | |
print "*" * 30 | |
print "*" * 30 | |
xml = unparse(doc, pretty=True) | |
import requests | |
headers = { | |
'Content-Type': 'text/xml', | |
'SOAPAction': 'http://MMIT.Gateway.WebServices/SendMessage' | |
} | |
print xmltodict.parse( | |
requests.post('http://test.services.multi-mit.com/Gateway/MMITGateway.asmx?WSDL', data=XML, headers=headers).text | |
) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment