MediaMath / t1-python

Python SDK for MediaMath Platform APIs
https://developer.mediamath.com/
Apache License 2.0
18 stars 30 forks source link

Fix for control characters #6

Closed pswaminathan closed 10 years ago

pswaminathan commented 10 years ago

API has started returning a control character, for some reason:

>>> import requests
>>> a = requests.Session()
>>> r = a.get('https://api.mediamath.com/api/v1/session', stream=True)
>>> r.raw.read()
'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x035\xcdA\x0e\x83 \x10\x85\xe1\xbd\xa7\x98\xb0aWu\x8f\x90^\xc1\x0b\x10"\x13KB!\x9d\x19\x8c\xc7\x97D\xbb\xff\xdf\xf7\x8c;\xbf\x19\x0e$N\xb5,z~M\x1a\x9c\x1d\x0c!\xb7,v\x000,A\x1a\xc3V#.*4\xf9x\xc2_K\x84Q\x01a\xe0\xbeS\xa5\x8a\xcfu\xdf1\xfaT\x94}\xf7\n\x8b\xa4-Hga}z3\xdeV\xf7\xc7\xff\xc1\x051\xc7\xe7\xac\x81\x00\x00\x00'

That \x1f is fine for UTF-8 but not for XML.

>>> ET.parse(r.raw)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 62, in parse
  File "<string>", line 38, in parse
cElementTree.ParseError: not well-formed (invalid token): line 1, column 0