How to download invoice images from Coupa using Python

394 Views Asked by At

I have a csv file with the url for a list of invoices in Coupa. I need to use python to got to the Coupa and download the image scan PDF file to a specific folder. I have the following code. It runs but when I open the PDF file it comes back corrupted. Any help would be appreciated.

import requests 
file_url = "https://mercuryinsurance.coupahost.com/invoice/15836/image_scan"

r = requests.get(file_url, stream = False) 

with open("python.pdf","wb") as pdf: 
    for chunk in r.iter_content(chunk_size=1024): 

         # writing one chunk at a time to pdf file 
         if chunk: 
             pdf.write(chunk)
0

There are 0 best solutions below