Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Curl command in python

Tags:

python

curl

cgi

I'm running the following curl command in CGI script in python using os.system call as below:

os.system('curl -u username:password -X PUT example.com/data/data1.txt -T /diskless/desktop/file.txt\r\n')

Getting the below error when I run the CGI script:

'!rl: Can't open '/diskless/desktop/file.txt') curl: try 'curl --help' or 'curl --manual' for more information.

Any suggestions please?

like image 900
Krish Avatar asked Feb 03 '26 16:02

Krish


1 Answers

you can use subprocess

import subprocess
command = 'curl -u username:password -X PUT example.com/data/data1.txt -T /diskless/desktop/file.txt\r\n'
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
like image 116
mrkzq Avatar answered Feb 05 '26 04:02

mrkzq