how to parse the response in python?
<p>I am sending a request nad getting a response from the server as res in my code below. Later I am parsing the file, file contains the text and the binary as shown below. I want to parse the file and separate the text and save it to .txt and binary information into .pcm. I have shown the response just for one message. I will be sending the message one after the other as a request and server will be responding to it as res.  I am having a problem to parse that .
someone help me</p>

<pre><code>    res = h.getresponse()
        data = """MIME-Version: 1.0
        Content-Type: multipart/mixed; boundary=--Nuance_NMSP_vutc5w1XobDdefsYG3wq
        """ + res.read()

        msg = email.message_from_string(data)
        print msg
for index, part in enumerate(msg.walk(), start=1):
            content_type = part.get_content_type()
            print content_type
            payload = part.get_payload()
            #print res.getheaders()

        if content_type == "audio/x-wav" and len(payload):
            with open('output.pcm'.format(index), 'wb') as f_pcm:
                print f_pcm.write(payload)

        elif content_type == "application/json":
            with open('json.txt'.format(index), 'wb') as f_json:
                print f_json.write(payload)
sys.exit(Error_Status)
</code></pre>

<p>response from the server : res = h.getresponse()</p>

<pre><code>----Nuance_NMSP_vutc5w1XobDdefsYG3wq
Content-Disposition: form-data; name="Audio"; paramName="TEXT_TO_READ"
Content-Type: audio/x-wav;codec=pcm;bit=16;rate=8000
Nuance-Context: a5a6e193-4a6d-468f-aea1-cb10d0c002fa

                   êÿûÿøÿ M ? w ûÿA àÿúÿ¡ lã _ #c #â Ðÿ‚ÿe «,ÎÿœüàûÜýêÿöÿHÿîüüšóãä øÅ~6ùsååê7û7“‡þÿ½þª
ðÙn‘jBÚ )/Ä#‰
räõÓgîº òVú#êcð!ùûŽóñ;î§ñZìƒäŽß…åð&amp;õhñžíûééëìðŒõNüVýmÿÅq#ï›"Ý)0ª8„&gt;Kš(HËÔ¿^Ù¿+ŸG.ôÓÕ*êuVÞÓïÁîÙý¯ù—óÆâ¥é¿ùx‹ÇþW÷Éû÷»ïØßÆßï»ú×ûð‹çâæ[í˜ôIöƒøtø ÷¢öÈõ¶þR   þ 3"&lt;&amp;N-:6I?•CçAçô§Õºß Ò?Ì.š ãmé¥ ¨ËúUðKäñïãëãâ‰ëÚñæïvêHé+îÀìûæ©â+è”ô_ûù;ò
ñÂófø#ýAy
%ÈÞÛ%r+¸4‰@)Oî7^ÞÞáå&amp;W-ŠxôBñTùÅÿÛîÒì¼çêì"ësçÔé©ë™ìRé­ènï4ñVîÈåã«èóñÊöÝõŸó=óöŸùxüýÿÜ³ÿüLx%ü(]1è9MÈFK"ÿüŽÑ~ç¤
8º6
€ïåáÖôà ÙþXïäåªâå!äòããûá éRí­ðíŒæôááçÒï‰÷úì÷ÃôôgùÚþ%N›
3æ,¤8„;LK&amp;D+-#\ä€ì¬
‡(&lt;'t
Ëò ñFøÒœüåð•çòåIéÞè`æÈáúÝéà¾éqílî·ç    á*Ü3á²ìÔõbø‹ó—îðøõIUÄ “ù  Òa!U$ó-ú7¤?ýKo8|ø©éX+#/þ8÷×ü_úüÜð/ì£ïríEëâ/ÞÕàøàïè í8î¯êß–ØtÜŒëÂ÷‘øèòí8ïV÷lÿÏ›†±× mZ;%L)0¸&gt;J1î$('&lt;$Ïßêíû¦C'BÅð’ðSó€ü&amp;ÿšî'ñï¦êêå!ì©ñÚééß(Ü&lt;çîwäjÖÑØ¤ëü7ûñìEæí°ú¼òÈývÿ®î
À
z &amp;#.g2-22B-ø%ùsêÐ¥ÂÿªøVüÐÿ¿ù}ðHì&gt;ò2ó5ï‘çgåQç´æ9ç–èBêAèÊÚšÌÏØÄïWÿù&lt;çã!ï±ÿšôý”úÚÿ[é 8[$6S?ú6]EŸ%(ŸXÿáû`Å–‰Šòcð“ì/øDöí—ëæç’íîæ”ãµæºçzæòÑ%ÈéÜnø||õäá‹ãRôœaû%þ†Ê­_$w,¼8K@9c( 
)ø ùÒþ
&amp;û­ôØÿ
“ºþû‡ÿ&amp;Äþ…n
Ãÿ÷ËòGýº¾ÿ0Kþ‰ýLýÐÿWú„ïµ ?þàý§ÿñêQ,ûIúúrýÐÿçÿ¹þ¾ÄÿÐ ÷  þ´vr£ýÓü›ýˆRðØüúúhþ¬ü^¨¨Âüû'ûŒ|/–
ý¤ûxý13à~üÄþ(üÃ úüþóþ- ðÿ²øný~¤›þ¯ÿäÿbÿ%2Ë Žÿÿ“ÿÔÜOþIüFùî×–ÿùÿ^ø ÿùüF üaÿ¦ü düZšüüþføyú³%
^äüWöÄûÿ&lt;c¿~WþÐùg Ã¹‹nÿ5ü%ýCþ¢ê½»ý²ø®üþ‘þµ (5ÿþÝýÞþFþ1ø×ü þ¯oYúô¤ýÛÙ´kýúW Ñ   05Zçs&amp;ƒÀ$@*‡þ¹þÅoÛÿ¤ú÷óò¢ùõöÅõõÐ÷%ôØôÌô2óXòDõ÷:õ ô‹ù–þáÿù” H.ˆö`›&gt;ú:ëPzsR@Û{&lt;ùçù³òZëpêtëqëçðáuß¶ÞBà!ßIßjàÅâÔå±ç2ë(ðhô(ùýŽý(dH
ø1¹¼!²"µ#M&amp;A*á2€4þ3ë3p0×3æ ó[ç“é’ýêDÙÞÖÃÝ!à&amp;ãºÚ~ÕÓôÑCØÞæ°éèè¬çgêÞðkõÐúþäþZŒß£ #:%$'t+ä*52&amp;4¹?ü8xI+bôÝ$à*&amp;ö!§)ätÖcèÿæÁí@â@×²Ó‡Ñv×äáæâ£ê âàbÝþÝßá˜è‰íüõ„ö üüúðÿ[Kè}¥!€&amp;3v7—;©=ÄBmNÃè~ÐxâÊ2'TÿÞÞÞÓëäî‡÷tåîà[Ù½ÙqÖ™ß,åï–éîç`ß™ÜiÝ!ãÔéÃñ˜õ’÷Äønú:ÿbN
—²„z!ü'12Þ8Ê?2=e@ò4Šÿ­ägÛGþ^"ã)Q–ö­ä}é2î¸ð4òGêÍêÍæ#âíÜÑÜè    îéê£ç&amp;áãàÅãsæ0éÍìªðõöõgùmûSý–ì    ÔÔêf$  -5Ü?á&gt;m5˜(ž,K
øEì/ù¬(CÌîççê”êÞñ×ïcìwé%æAäCã~ãÓèÊæ:æÛäàÆßJä;éïuñ|òTôƒöAú?ü; €Syè˜ '”/ï7uC`Ež3“
ëŸ ÀùÓþC
+/æ±ðAæœå‰íó½òòìsêßêíêkçòã¥ä'ç¸æLçRßUÚºà‰èòˆó¿ñXóƒõ¸øÂúkú²wÌ?ÃZ#/,5ÐAPIl7¡•[Ñàÿp$
óùTëôê ð'ôhð
ìkéÀï]ð4êZä©ä2è.çpÝG×dØÕãì¤ï¬ïWó/øËú‰ù´ûŠí
oò#¡*#3ø@OK]:uB
BžP   Ð^Q4ýùòðŠô¹ö­ð¸ëêoïÍñìéæééªà¯×VÒFÝ•ç¹î{ï·ï•ô}ø¬úˆú&amp;ÿÀÔ° }%Ì-z3ÊBŽCv)=mîïû3È   »³OüöøÀùtõÔð›í·íÅðî‘êÈç·éºçùÜÖÇÖÞÝ‚æè¿é®ìÿñSöv÷²úå«g
p'®-U0ê:÷8^)Õré*Ð  È;
&lt;
¦û†ø™øFøMõÝðï^ïfïígéæÝæºåàÝ•×@Ù\Þå7èòé½íó÷Où)ý¬î
€#r)|/â8˜8++øuL¬Ø{ Ý›
œ   æºûŠù!ú=ø½ôTðÖðòò#îênçîç´ã²ÜÙÚ{ß¸ã‘ææéEî’òÿõbùþHG    ;Ë o(s/\7)3¡(š½º¬i0ÿnå#Àý'üëù¬öHó!ñÇñƒñ5ïÝë¾èµçjåóßEÚÞØ«ÚqÞ¾á‘å*êµîAón÷5üÀ I+h#ž+K4K6Ò/Ù'Ê êQ{2¨¯Ýþ\üOúFöžòúïïï&amp;ð&gt;îfë-éræäá ÞcÛ­ÚµÛæÝ&gt;á‹å1ê†î|ó"ù&amp;þŸ»7ö#Á,·4Ü5Ó0ª)¦#)WÐk~€Vý_úÁöIó‹ðï¤î‘íeë
èóãîàúÞGÝ¨Û÷ÚèÛ1Þhá)åˆéïî·ôÞùËý4"@,¾8#ï,_6ï8X5//Ò(á#*m2þø*ýóùÌõäñ+ï(í¯ì:ëŸé³çäUá»ß1ÞöÜìÛ$Ü7Ý¼ß ãHç™ìlòü÷‹ü /g   •­`~'²0ý7^8A5‚/Ž)À#5o7v [Šþ-úÆöªòbïDíì ëlé_çã%á¿ß¦ÞÀÝ°ÜhÜ„ÜâÝ…àväÒéÈï¾õ!ûvÿxÄúV«:#O,œ5&gt;:9.5ð.±( "„þ v}ÿÅú$÷9ó¡ïàì
ëÏéè/æ´âŠàCß±ÞTÞÈÝ4ÝüÜyÝBß‹â3çäìÑò5øïü,\
iÚh$&amp;i/¿7o;\:55ÿ.&lt;(!¦…äù &lt;hýøõ*ñî±ë1êéDç¦äâ_áßàŒà àŽßÛÞ´ÞPß6áÿãÄç7ìñÕõúlþ¥É=F`\.%Ž,Ã4W::|5´/D)‡":$Nh
DýTørô.ñ›íDë˜éýçJæ%ä]â~á”áÎáá”à€ß›Þ–Þ+à-ãlçcì‚ñ‰öûú)ÿ#æŸ|€ ù(c1X9&lt;ò8u3æ,Ñ%D˜9²Lÿú)öó\ïxì¶êMéègæ
å'ä»ãäßããâá1àEß˜ß)áQäTèÿì%ò   ÷çû] iÃV
ô !
*m2Ý9(;ü6¡1Œ* #Úž‹  «ý
ùcõ6òŸî9ìGë-ê!éè)çç1çùç]èçVåäéâçâêã¡åoèÛëÃïéóØ÷âûÓÿgJ‡E•¾#8+@3s7Ò5J2á,§%v3…[®ùÿ²ûZøaõò8ï{íöë|êWé‚èMè7èyèé)èíæ§åäœãäJå®ç§êHîŒò«öœú†þQÑ    É^ó_%§+ý/0þ-
*$^~"ö’°ý„ùÔö¾óÐðßîLíMìsë£êFêDêRêˆêyêñéàèççÀç`èƒéë5íÒï®òßõ$ùGü6ÿB)œš    ‘§
°wÒ $&amp;’%Ü#É ï§è   Ñ³ÿ·ûhø7ö¤óÛñ1ðöî›íèìjìYì^ì´ì
íJííÁì‰ìíî»ïúñsô÷özùÓûþ §c)(«û 8Õ[MC™áõB5:Z‡P8å   —Òœþûï÷  öÏôôEóªò4òÂñiñAñˆñ£òõó õ÷õ¿ö°÷ ùcúÎûý-ÿˆ |ŠåBž±êÒ§Z:PÏ ª;ýh=f:àí/D¨ äÿbÿþÙýýý¾ü]ü'ûéùöžðî\ó¦ûß£
s¶ýfþ€ÀoýõBñøÒe
X¼ÿiú;ýÖiŸÕ„üÄû\•I¢Wþý2 &lt;Y‹‘eÿñÿ½ºúc )ÿÀþUÿÿºÿ
ÿ™ýæü`ü¼üLý¾ý7þþêütüIüÔüþþýüýþ6 ` S þÿ” V5_¬jAÀúfóuù£û] ¶E  ´=É^Õ6¯   ‘òþ‚üÁúùãö(ô_òoïðñgð8òCñ¾ðñæòPö(øsùÀú¾ûÒþQÛ¦ñ;÷t$; j¢²1’kÆúLôDïìˆê¼é¨êÏë1ïcô{ø°üÀýÒýÛý‚û­÷œò¡íºè`å;ä5ã¾ã­æïêºðÑø&gt;ûa°ÿ/$‰)a-Ì2Z6Í0( °,Àÿçó…ê\äÚà†ß=ßòà
ç¾ï7øˆÿ&amp;ÌI
1
þwÍú½óHê(ã)ß’Ù¾ØžÙuÜ&gt;ä6ì&lt;ôÇýìrj"¡'%-i3é9&gt;«7%+õ Ki’
ýZð…çÓã‘ßÐÚÄÛÚáÞéUólûºÀ
è
vü?öWðµæfÞÐØªÔTÔˆØÝ¡ã™ía÷.‚ûÂ%#-ê3:ª?‰=í.®#ƒ$Û÷úÝîIçÄãàÜ­×.Û‡äêëó üXO~bqÓâ%úÇñÄéZàÁÙ³ÔÞÑ—Ò%ÖÝÜ½äôî­øŒ†Ñ$W+Õ0ˆ7+=&gt;Ã2¼$§¿ôpþôÂíÊçÞß‘Ø ÛÊäõéxî¬÷ò.ùØ"²—Ãû|ö î/å¶ÝÀØÜÔ ÔÕ°ÙPáwéÀñ÷úþÊ
tïð#  *î/ 5:–;à1%T!WÀá °ù~ñ­éáïÛ8Þ±äÉæëÀõ _Ü
yŽ”
.AýCúòzç2áûÜÚØÕ]Ô¦Ø{ßÈå¾ìöõê €    Å¡û Ò&amp;j*ï1(8Š&lt;Z8/*H$D$o‹Í _ûî×ãŸßÝÝëàââå£ïkú±ÿ;Úµ
ž¡ |ÿôôÕêç
á€Ú Ø×±Ù¢Þšã´ë`õ[ýõ´]£j#(‡/ö4­9N9-O&amp;.%¯¿    œŠýðwèðâUÞ¹ß…áõãÛë&lt;õqûJ…
m€vÿ~õ-íìçòá-Ý-Ú°ØSÜlàÑäíìuõÍýU¬§D"J&amp;®- 2R8 7/W)¬#ýÇÞýõMê~ã¯à
àßoãŠê»ñä÷¿þ™êôÀ@ÿëõ ñËë5ãÕß´Ý7ÛyÝºß”ã}ê2ðêö|ÿ/ì•

3"q%£*™0ç5Z4›.]'Ì$u
öXòêéWç¾ßÓÜJàTã@é„ðQöYþÀž*XÃ ‘ýBõîîªèÿàÞZÝâÚÉÝãcæLìäôAû]0 °¡o:k "Í&amp;²,u22É3f)“"%½&amp;8°ú;écìãÙöÝ á ãyëòÁùòþîÒÏÿ@ým÷ðßéã/ßÜùÛoÞqá_æyíîó
ú&gt;ïçìŸM°D"Ì'%+&lt;4î1ä/ã*Ø$öëªÓ™ôÈëé9Ü¡Ù+ß2ß@ã±íò&amp;úŒÿüÝÀôþàûyô•îóçÆá„ÞpÜEÜJßãâ#èïÒõšüó?    ªðIRÓ!(p.«1§0y2(X#­!¦E
môë’è9ÝÚëÞaà§ãsì™óåøý÷
ÑÿýOñÏï’êVßPß8ßŽÛºÞäãçríÁôæü¡Kï„#Z    ´"‰(A*\3š2|--%¥n±%úŸíÔç—àkÛ%ÞÃßÃã„ëSñŒøþá ñàÝÿyý³ö]ðÅê;äàÌÝöÜ-ÞÖá‰ædìüò¨ú 6
«u;¾îZ$  (.Q/^-.%¦lÛ¨ Þð0ëPåúÝvÞ
àwãéYîyötúÙýóq  fþ÷4ó&lt;í†æ}âëßÞŒÞ àrä²èmî{õåû_SNú‹Gó² $ú(×-§3J,í,*uèˆ]ÿà÷^ê˜ærâ&lt;ß!áºä&gt;êî¼ôü²üÿýüKúøöoð¡ë¯æãáŽßÆáÌãÉæxí.óZùXÿƒc})dA!B#(/›2ô'@*2*â:‘ýiûØì èê¶çjæ^ë÷ñ¿ðKôü!÷½õæ÷ò˜ìì=çFãá@âÝá%äŽé¶í¶ð÷ûæþKœ!í
í)_ 
$¨)V4Î7L-ê0x/WAL Oü,û3ëdè?é¸çßæðéUòìð,óú$öœò9ôƒîÈéÓèìäýââãåÕç)íñôÔøEüRý  zBŸ    ðp#ã)È/Ë;ë3P+ü2"íé§Þ÷ñ÷òó†ë’è"ï£ïÃëüôBùò™ö
÷-î|ìPêcå¿â
âã âøãåçYë‰îZò¦ô“÷JùûÁþ,ÿÖ³˜    ø
½€ÒÌ#·,Ë/827¥(Ä,Ý"vÁþûúSù óïõñ¡õÔïñúö-ð‘îêïÒêvç†æšåiä»ãwåçÃæ»é4ìjî+ñ¯òõyø
ú&gt;þÈÿžÍ­  Ÿ
Ð-°¶.'ê.”2h9Ü+ƒ&amp;F&amp;+
Ü¦Îû÷ùÅù9÷;ò°õ·öÏñ‰óLòiïÒîaêèDèÄã+äMå9åðäFæËæ‘éìLîòðó õùü¿ÿ
øÉ    Ãùó,Ã &amp;.|1=Ÿ0þ &amp;”·Ìá&amp;þ™üüÕýYöh÷Ñø&lt;òÙð»ñµë©íwêªçàè¾ç4çéúç®éëçzç
é¤ê‘ì9ïÝðèó÷§ùþ  Mi"k`žŒÉ#´)³1x3G&gt;è,¡¹ÈãÒcýûìÑüëö&amp;öÄñEò¨îè|ìõìõèÙé‹ê/ì[ëŸéÄêµèNçèêAí²ðòñõ¾öÅø°ü
þøÿ’¢éP’"U&amp;Š.5Ê?¨1‰Ì]ÜþÉ      Ó   b G ÿ§ù•ô%ëŒí­ðoêèêGîÍîÂîÛìäíbîßëÐêCêéìè·êì‹ï_ó…ôIö¾öø÷ùàúÊý&amp;“V³ýÏë$(Æ/¹2{&gt;Â/;kAœ~+ê »  ýÍõböºñ!ìèíVïVî»í°íEñaðEîØîÎí&lt;í×ì^êœëjìyë
î}îýòŠöõõ½õŒö‰÷ýø™þë´‚²F‘!‹'¤(°.S5&lt;Ÿ%^õ  ­
 
M¤ÿÀô6ïkðâòOìì¦ð`ð³ï“ìÿí³ñìïëíJìÇîFí¬ì÷îÚïqïÊðƒó!õôéò›ôè÷²÷úùQ Â
\æÖ{#½*í'#)41ê&lt;ƒ*¾
UáKpS ¸øvêŽíWóòóœïìêFî@ò1ð”îÊíÝî˜ðð%î•î‚îæïŒï³îyðºð„ó¢õ¨ó½ñþðÊójøQú¼ý§ã &amp;
ô
d                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
----Nuance_NMSP_vutc5w1XobDdefsYG3wq
Content-Disposition: form-data; name="Audio"; paramName="TEXT_TO_READ"
Content-Type: audio/x-wav;codec=pcm;bit=16;rate=8000
Nuance-Context: a5a6e193-4a6d-468f-aea1-cb10d0c002fa


----Nuance_NMSP_vutc5w1XobDdefsYG3wq
Content-Disposition: form-data; name="QueryResult"
Content-Type: application/JSON; charset=utf-8
Nuance-Context: a5a6e193-4a6d-468f-aea1-cb10d0c002fa

{"TTSStatus":"Success","result_type":"NVC_TTS_CMD","NMAS_PRFX_SESSION_ID":"11945be5-3802-4ecc-86a1-f5b51ccf7c9d","NMAS_PRFX_TRANSACTION_ID":"1"}
----Nuance_NMSP_vutc5w1XobDdefsYG3wq--
</code></pre>