0

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?

khelll
  • 23,590
  • 15
  • 91
  • 109

3 Answers3

3

how about using a library instead of calling system's curl?

ghostdog74
  • 327,991
  • 56
  • 259
  • 343
  • Because sometimes you do not want to wait for a response or wait at all, just fork-detach and forget. Like when logging. – rapadura Mar 13 '14 at 11:33
  • Another good http python library is '[requests](http://docs.python-requests.org/en/master/)' library – Mercury May 26 '16 at 11:18
2

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)
Ross Rogers
  • 23,523
  • 27
  • 108
  • 164
0

How about using requests library

Python POST binary data

Or yet another

Check out this link for binary (image file) case How to download image using requests

Kishan K
  • 671
  • 7
  • 18