Curl works fine except when I call it with a subprocess

I have a curl that looks something like this:

curl -1 -X POST --user "xxx:yyy" -d "status=new&content=issue+details+at%3A+http%3A%2F%2Flocalhost%3A6543%2Ftest%2Fsubmit%2F16-07-03-H-20-18-&kind=bug&title=QA+Fail&responsible=xxx&priority=critical" "https://api.bitbucket.org/1.0/repositories/my/repo/issues" 

If I open the terminal and just run it, it works fine (the problem is being created in the bitpack)

if I try to execute the same curl through a subprocess, it just fails:

 sCmd = "curl....etc" lCmd = [s for s in sCmd.split() if s] subprocess.call(lCmd) 

I get an error message:

 curl: (1) Protocol "https not supported or disabled in libcurl 

I do not understand why the same command works differently in Python. Any ideas?

This, by the way, is without using virtualenv. And I know that the contents of lCmd valid

PS: yes, I know I have to use queries. Unfortunately, the queries caused me similar problems.

+7
python curl
source share
3 answers

If this is helpful, please support Andr’s answer, he set me on the right path.

view error message:

 curl: (1) Protocol "https not supported or disabled in libcurl 

see "https is a problem, https , on the other hand, works great.

The problem was that I thought I had to enclose my arguments in quotation marks.

So there are two easy ways around this:

 lCmd = shlex.split(sCmd) subprocess.call(lCmd) 

or

 import os os.system(sCmd) 
0
source share

I cannot answer your question about using the curl command in subprocess , but it might work if you just call os.system Like this:

 import os os.system ("curl -1 -X POST --user \"xxx:yyy\" -d \"status=new&content=issue+details+at%3A+http%3A%2F%2Flocalhost%3A6543%2Ftest%2Fsubmit%2F16-07-03-H-20-18-&kind=bug&title=QA+Fail&responsible=xxx&priority=critical\" \"https://api.bitbucket.org/1.0/repositories/my/repo/issues\"") 

This most likely works, knowing that curl runs directly through the terminal.

This may help with your question that curl does not work in the subprocess (perhaps this is because the subprocess environment is different from the environment in which curl is configured): https://curl.haxx.se/docs/faq. html # curl_1_SSL_is_disabled_https

+1
source share

The only time you have a wrapper in this scenario is to split your string into a set of arguments.

The fact is that you do not need anything for this - you can do it more accurately and consistently!

 subprocess.call([ 'curl', '-1', '-X', 'POST', '--user', 'xxx:yyy', '-d', 'status=new&content=issue+details+at%3A+http%3A%2F%2Flocalhost%3A6543%2Ftest%2Fsubmit%2F16-07-03-H-20-18-&kind=bug&title=QA+Fail&responsible=xxx&priority=critical', 'https://api.bitbucket.org/1.0/repositories/my/repo/issues' ]) 

It also avoids the confusion between literal and syntactic quotes: when specifying the argv literal, the literal Python string you pass is the literal string that the child process receives β€” there is no need to pass quotes to the shell.


This is much more reliable than starting with a string and breaking it, even with built-in built-in Python. Consider the case when your username contains spaces. List containing

 '--user', 'user name:password' 

... completely unambiguous, whereas

 --user user name:password 

... will be parsed incorrectly.

Worse would be a username containing $(rm -rf $HOME) - if you use os.system() or subprocess.Popen(..., shell=True) , this username can be executed as a command; with a literal string, you are absolutely safe.


The above is a specific error, re: libcurl, not compiled with SSL support, will not be call-specific. I would suggest checking your environment - if you have different versions of curl first in PATH or different versions of libcurl in LD_LIBRARY_PATH between your environments, this will explain this error.

+1
source share

All Articles