Deployment by using Python throws error:
I used Python code ( its your deploy.py) to deploy our proxy (our company proxy) into apigee platform. i read http://apigee.com/docs/api-services/content/deploying-proxies-command-line
but it throws error when i run "python api-platform-samples-master/tools/deploy.py -n apikey -u "yusuf.karatoprak#mobgen.com:Welcome#2014" -o yusufkaratoprak123 -e test -p / -d sample-proxies"
i would like to solve this situation. i added to python code it is not working. it throws me Error: name 'ZipFile' is not defined
The -d flag value needs to point to the directory that contains the /apiproxy directory for the sample you want to deploy. (In your command above, it appears that you are pointing at /sample-proxies, rather than, for example, /sample-proxies/apikey
Try using the deploy scripts. There is one in each sample proxy directory. There's a also a script, /setup/deploy_all.sh if you want to deploy all sample proxies.
Make sure you update /setup/setenv.sh before running the deploy scripts.
The error is in how you are calling it from the command line. You have a space in one of the parameters you pass in, which needs to be put inside of quotes. Turn -u yusuf karatoprak:123 into -u "yusuf karatoprak:123"
Fixed command line call:
python api-platform-samples-master/tools/deploy.py -n weatherapi -u "yusuf karatoprak:123" -o yk123 -e test -p / -d simpleProxy
Related
I am trying to use Pidcat for logging. I downloaded the Pidcat.py and pasted it in the following directory:
C:\Python\Scripts
Added this path in the Environment Variables as well. But when I try to log in using the following command:
pidcat -s deviceId
I get the following error:
Unable to create process using '/usr/bin/env -S python -u "C:\Python\Scripts\pidcat.py" -s deviceId'
I used CMD to run a python file getofflinelog.py.
The command is:
python getofflinelog.py -m txt -d camlog -o offline.log
I got a similar error Unable to create process using '/usr/bin/env...., and I solved it by changing the command to:
C:\Users\liutongjun\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\python.exe getofflinelog.py -m txt -d camlog -o offline.log
I also found that if I added this path to the environment variables, the first short command would work.
I'm not very clear why it works, I do not install Python in this path and there are only a series of exe programs in this folder. Just for reference.
I am trying to run a docker container, specifically openalpr found here:
https://hub.docker.com/r/openalpr/openalpr/
docker run -it --rm -v $(pwd):/data:ro openalpr -c us plateTest1.jpg
I am running into an error in python when trying to run this command as a subprocess:
import subprocess
app.py
result = subprocess.run(['docker', 'run', '-it', '--rm', '-v pwd:/data:ro', 'openalpr', '-c us', 'plateTest1.jpg'], capture_output=True)
print(result.stdout)
print(result.stderr)
Here is the error I am getting:
(base) mac#macs-MBP lpr % python openalpr_test.py
b''
b'docker: Error response from daemon: invalid volume specification: \' pwd:data:ro\': invalid mount config for type "volume": invalid mount path: \'data\' mount path must be absolute.\nSee \'docker run --help\'.\n'
I am assuming this has to do with escaping slashes?
When you call subprocess.run([...]), you are responsible for breaking the command into "words". There is no further processing here; everything gets passed on exactly as you have it.
In particular, when you
subprocess.run([..., '-v pwd:/data:ro', ...])
The argument passed is exactly -v pwd... including the space in the single argument. Docker sees a -v argument and parses the rest of this "word" as a volume specification, breaking it on colons, so mounting a named volume (with a leading space) pwd on container path /data in read-only mode. Since (space) pwd isn't a valid volume name, you get this error.
You can break this into two separate words to disambiguate this, or remove the intermediate space.
subprocess.run([..., '-v', 'pwd:/data:ro', ...])
subprocess.run([..., '-vpwd:/data:ro', ...])
(In general it's better to avoid launching things as subprocesses if there is a native library or SDK that has the same functionality. You might try to run this process using the Docker Python SDK instead. Remember that it's very easy to use a docker run command to root the entire host: be very careful about what you're launching and how command lines are processed.)
Not exactly the way I laid it out but this seems to work:
from subprocess import Popen
import subprocess
command='''
docker run -it --rm -v $(pwd):/data:ro openalpr -c us plateTest1.jpg
'''
process=Popen(command,shell=True,stdout=subprocess.PIPE)
result=process.communicate()
print(result)
In python I am trying to execute a fabfile and ,I get the below error from the subproccess output. I installed fabric using easy install. If I run the code from the command line it works. From python no go. I assume there is an issue with how I am using the Popen command?
/bin/sh: 1: fab: not found
Below is how I start fabric from python:
cmd = """fab -H 111.111.111.111 aws_bootstrap initial_chef_run:aws_server.json,aws-test,development -w """
os.chdir(fab_path) #change to the dir where the fabfile is located
p = subprocess.Popen(cmd, shell=True,stderr=subprocess.STDOUT,stdout=subprocess.PIPE)
PS I added the below to the Popen but get the below error:
executable="/bin/bash"
/bin/bash: fab: command not found
From the command line I get the below which means the terminal can find fab.
fab
Fatal error: Couldn't find any fabfiles!
Remember that -f can be used to specify fabfile path, and use -h for help.
Aborting.
Try to use the whole path for fab. To get the path to fab on your system, you can use which fab.
However, I can't think of any reason why calling fab from python might be better than using the execute function of fab:
from fabric.tasks import execute
import my_fabfile
r = execute(my_fabfile.aws_bootstrap, hosts=["root#%s" % '111.111.111.111])
Return value r will contain a dict with the hosts as key(s).
I am trying to run a python script on a remote computer via psexec. I am able to connect and run python.exe with the following:
C:\test>psexec \\192.168.X.X -u domain\administrator -p password -i C:\Anaconda\python.exe
The path to python.exe is the path on the remote machine. This opens a python window on the remote machine - all good.
I want to now pass a python script from the host machine to run on the remote. This script is on the host machine in C:\test\test.py. I tried
psexec \\192.168.X.X -u domain\administrator -p password -i "C:\Anaconda\python.exe" -c C:\test\test.py
and get:
C:\Anaconda\python.exe exited on 192.168.X.X with error code 1.
I also tried-c test.py without the full path, and got a similar error. My thought is the remote application cannot find C:\test\test.py. I want to be able to pass the script from the host machine.
Any help is much appreciated. Thanks.
If the .py extension has been associated with the Python installation on the remote machine, you may be able to run your Python script by simply removing the Python executable from the command line:
psexec \\192.168.X.X -u domain\administrator -p password -i -c C:\test\test.py
Please note that I have not tried this as I don't presently have access to a remote machine, so I can't guarantee that it will work.
The line
psexec \\192.168.X.X -u domain\administrator -p password -i "C:\Anaconda\python.exe" -c C:\test\test.py
may be trying to run the command "C:\Anaconda\python.exe" -c C:\test\test.py on the remote machine. In other words, Python may be interpreting the -c switch, rather than PsExec. The Python switch -c specifies some Python code to run, and of course a filename is not valid Python code:
C:\Users\Luke>python -c "print 2 + 2"
4
C:\Users\Luke>python -c C:\test\test.py
File "<string>", line 1
C:\test\test.py
^
SyntaxError: invalid syntax
C:\Users\Luke>echo %ERRORLEVEL%
1
Was able to access a python script on a shared drive from the remote computer and host, and so by copying to the share from the host and reading from the share on the remote machine i had a suitable workaround (the -i switch is not required).
psexec \\remote_machine_name -u domain\user -p pswrd -i C:/Anaconda/python.exe \\server\share\test\test.py
Related: if you are running on windows and writing to a UNC path from a python script i.e test.py above, helpful path formatting help:
python copy files to a network location on Windows without mapping a drive
I try to use supervisor with perlbrew, but I can not make it work. For perlbrew I just tried to set the environment variable that go well, but perhaps it is better to make a script that launches perlbrew and plackup, this my configuration file:
[program:MahewinSimpleBlog]
command = perlbrew use perl-5.14.2 && plackup -E deployment -s Starman --workers=10 -p 4000 -a bin/app.pl -D
directory = /home/hobbestigrou/MahewinSimpleBlog
environment = PERL5LIB ='/home/hobbestigrou/MahewinBlogEngine/lib',PERLBREW_ROOT='/home/hobbestigrou/perl5/perlbrew',PATH='/home/hobbestigrou/perl5/perlbrew/bin:/home/hobbestigrou/perl5/perlbrew/perls/perl-5.14.2/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games',MANPATH='/home/hobbestigrou/perl5/perlbrew/perls/perl-5.14.2/man:',PERLBREW_VERSION='0.43',PERLBREW_PERL='perl-5.14.2',PERLBREW_MANPATH='/home/hobbestigrou/perl5/perlbrew/perls/perl-5.14.2/man',PERLBREW_SKIP_INIT='1',PERLBREW_PATH='/home/hobbestigrou/perl5/perlbrew/bin:/home/hobbestigrou/perl5/perlbrew/perls/perl-5.14.2/bin',SHLVL='2'
user = hobbestigrou
stdout_file = /home/hobbestigrou/mahewinsimpleblog.log
autostart = true
In the log I see it's not looking at the right place:
Error while loading bin/app.pl: Can't locate Type/Params.pm in #INC (#INC contains: /home/hobbestigrou/MahewinSimpleBlog/lib /home/hobbestigrou/MahewinBlogEngine/lib /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/lib/site_perl .) at /home/hobbestigrou/MahewinBlogEngine/lib/MahewinBlogEngine/Article.pm line 5.
I do not see the problem, maybe perlbrew use done other things
When you installed perlbrew, you added a command to your .bashrc. You're getting that message because that command wasn't run for the shell in question because it's not an interactive shell.
Why don't you explicitly use /home/hobbestigrou/perl5/perlbrew/perls/perl-5.14.2/bin/perl instead of using perlbrew use?