I would like to send a complex curl command into python (3.9.7) script to download an output file .tif I use a TimeNum variable because i want to download different files and clip the .tif in a personal area of intrest (I want to use a for loop).
The curl command is something like this:
curl --data '{"productType":"VMI","productDate":"1648710600000"}' -H "Content-Type: application/json" -X POST https://example.it/wide/product/downloadProduct --output hrd2.tif
I try different solutions:
1)
import shlex
import subprocess
TimeNum=1648710600000
cmd ='''curl --data \'{"productType":"VMI","productDate":"%s"}\' -H "Content-Type: application/json" -X POST https://example.it/wide/product/downloadProduct --output %s.tif''' % (TimeNum,TimeNum)
args = shlex.split(cmd)
process = subprocess.Popen(args, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
The download work but the output takes up 1KB instead of about 11MB, and an error occur when i try to open it in Windows.
- I write a txt file with a list of curl command line by line and then:
file = open('CURL_LIST.txt', 'r')
lines = file.readlines()
for line in enumerate(lines):
os.system(line.strip())
but don't work fine and i have the same output of case 1 above. Now i try to use urllib.request but i'm not able to use it very well.
Someone have a suggestion? Thanks in advance for your help