I'm trying to form a cURL using string concatenation in Python. I have a custom command and I'm not sure if I can use requests for this.
cmd='curl -u admin:'+password+' -F file=#'+package+' -F name='+package+' -F force=false -F install=true http://'+ip+':5101/crx/packmgr/service.jsp'
print(cmd)
Error:
curl -u admin:******** -F file=#abc_xyz.zip
-F name=abc_xyz.zip
-F force=false -F install=true http://8.8.8.8:5101/crx/packmgr/service.jsp
curl: no URL specified!
curl: try 'curl --help' or 'curl --manual' for more information
sh: line 1: -F: command not found
sh: line 2: -F: command not found
32512
And yes I have tried escape '' as well. Didn't work.
Any help would be greatly appreciated. TIA
Looks like your constructed command has line endings after the package variable, try stripping it from extra symbols:
package = package.strip()
Related
I am trying to replicate shell command:
curl -u [staff_email]:[api_key] -F "case[attachments][0]=#/path/to/file1.ext" -F "case[attachments][1]=#/path/to/file2.ext" -F "case[content]=I need help" -F "case[subject]=I need help" -F "case[user_email]=user#domain.ru" -F "case[user_full_name]=FullName" -F "case[language_id]=2" -F "case[custom_fields][cf_44]=3" -X POST https://[domain].omnidesk.ru/api/cases.json
into Python code using Requests library:
import requests
What is a proper syntax for this example (curl -X POST)?
You can use requests.post, as explained here
for the attachments part (your first -F), read here
for the auth part (-u): here
I am trying to store the output of my helm command in a variable in bash script and trying to echo it but it return giving an error ..syntax error in expression
Here is my code
MY_VAR=$((helm ls -A -o json))
echo ${MY_VAR}
To execute one command after another you must add && between them.
Also, you do not need double parentheses.
For example:
MY_VAR=$(helm ls -A -o json) && echo ${MY_VAR}
Its because you got double brackets
Change into
MY_VAR=$(helm ls -A -o json)
this solve the problem for me
I'm trying to start tshark with python. Testing the command in command line seems to be OK. but while starting it with python, I'm getting error as described below.
Any idea what is going wrong?
cmd1='"tshark -i 1 -Y "ssdp" -T fields -E separator=, -E header=y -e ip.id -e ip.checksum"'
cmd=shlex.split(cmd1)
try:
tsharkProc = subprocess.Popen(cmd,
shell=True,
stdout=subprocess.PIPE,
executable="C:\\Program Files\\Wireshark\\tshark.exe")
except:
print("ERROR {} while running {}".format(sys.exc_info()[1], cmd))
And the error:
Capturing on 'Ethernet 2' tshark: Invalid capture filter "/c tshark -i
1 -Y ssdp -T fields -E separator=, -E header=y -e ip.id -e
ip.checksum" for interface 'Ethernet 2'.
That string isn't a valid capture filter (can't parse filter
expression: syntax error). See the User's Guide for a description of
the capture filter syntax. 0 packets captured
I'm trying to download some data using a bash script in a Jupyter notebook and having some problems.
I added quotes to the file paths after I received a 'SyntaxError: unexpected character after line continuation character' error.
However, I'm stumped on how to fix the same error on the Wget command.
This is the contents of the cell as I have it now.
%%bash
FILE=apple2orange
URL="https\://people.eecs.berkeley.edu/~taesung_park/CycleGAN/datasets/$FILE.zip"
ZIP_FILE="./datasets/$FILE.zip"
TARGET_DIR="./datasets/$FILE/"
wget -N \$URL -O \$ZIP_FILE
mkdir $TARGET_DIR
unzip $ZIP_FILE -d ./datasets/
rm $ZIP_FILE
I have changed a little on your script. Now it looks like this:
%%bash
FILE=apple2orange
URL="https://people.eecs.berkeley.edu/~taesung_park/CycleGAN/datasets/$FILE.zip"
ZIP_FILE="./datasets/$FILE.zip"
TARGET_DIR="./datasets/$FILE/"
mkdir -p $TARGET_DIR
wget -N $URL -O $ZIP_FILE
unzip $ZIP_FILE -d ./datasets/
rm $ZIP_FILE
In bash strings : doesn't need to be escaped. That was the error I think.
It works on my end.
Have a try.
I have this command
curl http://localhost:6800/schedule.json | python -c "import json; print (' '.join(['-d '+key+'='+word for key,word in json.load(open('cron_parameters_testing.json')).items() ] ))"
actually the python command reads parameters from JSON file like this
{
'project' : 'default'
}
and returns the output as -d project=default
I have separately tested python -c "import json; print (' '.join(['-d '+key+'='+word for key,word in json.load(open('cron_parameters_testing.json')).items() ] )) command it works perfectly but it does work with the cURL
my final command that I want to run is
curl http://localhost:6800/schedule.json -d project=default
of course I want -d project=default to be generated from command I mentioned
| is a pipe, in your case it sends standard output from curl to become the standard input to python. This seems unrelated to your task. Try:
curl http://localhost:6800/schedule.json `python -c "import json; print (' '.join(['-d '+key+'='+word for key,word in json.load(open('cron_parameters_testing.json')).items() ] ))"`
The backticks (`...`) evaluate the command inside and get substituted with the output of the command. Alternatively you can use $(...), especially if you need to nest commands like this.