subprocess popen + curl + binary data
Question:
The following statement works as expected:
os.system("curl --data-binary @"+input_file_path+" -o "+ file_name +" localhost:30")
But when trying it with subprocess.popen
:
Popen(['curl','--data-binary','@'+input_file_path, '-o', file_name,'localhost:30'], stdout=PIPE).communicate()[0]
Curl seems to hang up(logs into endless loop), like if the input file is not passed to it(which is mandatory for localhost:30 to function properly)…
Any ideas?
Answers:
You could try using the original string in subprocess.Popen
with the additional keyword argument to Popen
of shell=True
:
subprocess.Popen("curl --data-binary @"+input_file_path+" -o "+ file_name +" localhost:30",
stdout=subprocess.PIPE,
shell=True)
how about using a library instead of calling system’s curl?
How about using requests library
Or yet another
Check out this link for binary (image file) case
How to download image using requests
The following statement works as expected:
os.system("curl --data-binary @"+input_file_path+" -o "+ file_name +" localhost:30")
But when trying it with subprocess.popen
:
Popen(['curl','--data-binary','@'+input_file_path, '-o', file_name,'localhost:30'], stdout=PIPE).communicate()[0]
Curl seems to hang up(logs into endless loop), like if the input file is not passed to it(which is mandatory for localhost:30 to function properly)…
Any ideas?
You could try using the original string in subprocess.Popen
with the additional keyword argument to Popen
of shell=True
:
subprocess.Popen("curl --data-binary @"+input_file_path+" -o "+ file_name +" localhost:30",
stdout=subprocess.PIPE,
shell=True)
how about using a library instead of calling system’s curl?
How about using requests library
Or yet another
Check out this link for binary (image file) case
How to download image using requests