Python-Requests Chunked XML Data Returns only First 2 Lines of Data

98 views Asked by At

I am using python-requests to hit a REST API that returns XML data to me via chunked transfer-encoding. The problem is when i run my program I only get the first 2 lines of XML.

I have tried tried hitting the api via Fiddler to confirm the API is working properly and it is.

Here is my code:

resp = req.get(results_uri, stream=True, headers=self.token_header, verify=False)

with open(outputfilepath, 'wb') as f:
    for chunk in resp.iter_content(chunk_size=1024): 
        if chunk: 
            f.write(chunk)
            f.flush()

The above code Produces:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<tag appliance="app" version="1.1" msg="concise" xmlns:ns2="http://vendor/schema"/>

But if I use fiddler to pull the same uri I get:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<tag appliance="app" version="1.1" msg="concise" xmlns:ns2="http://vendor/schema">
<ns2:alert id="13050410" name="object" severity="minr" product="app">
    <ns2:explanation>
        <ns2:file-detected>
            <ns2:file>
                <ns2:md5sum>4518b667438479516f8c9ae28b91df2f</ns2:md5sum>
            </ns2:file>
        </ns2:file-detected>
    </ns2:explanation>
    <ns2:src/>
    <ns2:action>notified</ns2:action>
    <ns2:dst/>
</ns2:alert>

0

There are 0 answers