Run a python command from a .yaml file - python

I have a python project working locally which runs under the UNIX command format of: python main.py arg1 arg2 etc.
I want to export my folder to the Google App Engine, so I did the small tutorial to make "Hello World" run on my App. I read the app.yaml file but can't seem to figure out how to add an app.yaml to my project that runs my Python command.
EDIT:
runtime: python27
api_version: 1
threadsafe: true
command: ["/bin/sh", "-c"]
args: ["python webXMLPARSER.py www.reitmans.com 2016-12-01 2016-12-08"]

The short answer - you cannot do that.
The long one now.
GAE (standard) app code is not designed to run as a standalone app. It is merely a collection of config files and code snippets designed to work together with and complement the GAE infra code (live or SDK) in order to operate as an app.
To run the app locally one must do it through the SDK's development server, see Using the Local Development Server for details.
Also:
GAE apps are fundamentally web server apps, they get requests and return responses, they don't actually execute arbitrary python cmds. Your attempted config is invalid, see app.yaml Reference.
the GAE sandbox has significant restrictions when it comes to what the app can do, in particular launching other processes is not allowed. See The sandbox.

First, you have to instruct to run a shell, and then pass arguments to the shell like python something.py args1 args2.
command: bash -c "python something.py args1 args2"
You should try Dockerfiles1, they have a more intuitive way of running commads:
CMD ["python", "something.py", "args1", "args2"]

Related

Running python flask gunicorn app from shell script

I build my flask app, it requires external files through the runtime.
when I build the app, meaning I run > gunicorn app:app (the app startup file is called app.py but that didn't bother). It runs awesomely.
Now when I decided to make a sort of shell script to execute it (actually to make a couple of dependencies and environment checking but for the sake of simplifying, I created startup.sh in the same directory as app.py and it contains only the following instruction unquoted: "gunicorn app:app"), it just throws errors.
and this is the last one ...
Please help..
yep just as I guessed, it should be run within the script inside a virtualenv so that it will execute python 3 :)

Get app engine info via api commands

Seems like google cloud's shell commands are super limited.
I can see docs about using appcfg.py to upload and download code from app engine, but what are the commands to just get basic info about it?
Is there a list services command? Or a get running versions command? I still don't understand where the app engine code I upload lives.
What are the commands to just "poke" app engine stuff?
To get info about what appcfg.py can do:
$ appcfg.py help
Usage: appcfg.py help <action>
appcfg.py: error: Expected a single action argument. Must be one of:
...
list_versions: List all uploaded versions for an app.
...
$ appcfg.py help list_versions
Usage: appcfg.py [options] list_versions [directory]
List all uploaded versions for an app.
The 'list_versions' command outputs the uploaded versions for each module of
an application in YAML. The YAML is in formatted as an associative array,
mapping module_ids to the list of versions uploaded for that module. The
default version will be first in the list.
...
A bit newer than appcfg.py and the officially recommended one these days (but still not covering all the stuff from the Console) is the gcloud CLI from the Cloud SDK (and in particular the gcloud app submenu for GAE apps).
Your uploaded code lives in the cloud :) Donno exactly where, but you can see it in the Console's Debug page. Not directly accessible from the cloud shell's VM (AFAIK). If you want to access it in the cloud shell you need to download it from your app to your "cloud homedir" (using one of the 2 utilities).
As for "poking", you have to be very specific as different kinds of poking are done in different ways (many in the GUI only). Probably better to do it in a separate question (or questions).

How to run a simple python script on heroku without flask/django?

I'm trying to run a simple hello world python program on my heroku server. I'm new to heroku.I was able to successfully deploy my script to heroku.
My python script and procfile are given below,
hi.py
print("hello world")
Procfile
web: python hi.py
I got "Hello world" as output when i ran heroku run web on my terminal.But when i try to run the app using heroku web url it shows the following error.
Application Error An error occurred in the application and your page
could not be served. Please try again in a few moments.
What did i do wrong here? I'm newbie to heroku & its concepts, please do bare.
There are three types of dyno configurations available on Heroku:
Web -- receives web traffic.
Worker -- keeps processing tasks/queues in the background.
One-off -- executed once. e.g.: backup.
If you're interested in running a script, do not care about receiving web traffic on it, and don't have a queue to process, then One-off dynos are likely what you'll want to use. This would be useful for database migrations or backups and whatnot.
Minimal example below.
Sample one-off dyno with Heroku and python AKA “hello world”
This assumes you have already created your app on Heroku and are able to use Herolu CLI from the command-line.
A minimal “hello world” Python script would then look like this. Only 2 files required:
requirements.txt Required, but can be left empty.
task.py with content print("hello world")
Then deploy to Heroku, e.g.:
git add .;
git commit -m "My first commit";
git push heroku master
After that, you'll be able to run your script with heroku run python task.py (and should see the long-awaited hello world in the output.)
If you want to run your program at specific times, use the free Heroku Scheduler add-on.
FYI, Procfile is optional. If you set it to hello: python task.py then you'll be able to run your program with just heroku run hello.
(Note that leaving requirements.txt empty will trigger You must give at least one requirement to install (see "pip help install") warnings on deploy. It's just a warning though and doesn't prevent proper deployment of the program.)
I disagree and state you want flask
main_app.py
import flask
app = flask.Flask(__name__)
#app.route("/")
def index():
#do whatevr here...
return "Hello Heruko"
then change your procfile to web: gunicorn main_app:app --log-file -

Cannot Deploy Pyramid Application on Heroku

I am having issues deploying my Pyramid app on Heroku. It runs fine locally but as soon as I try to launch it I receive this error "pkg_resources.DistributionNotFound: mymedaproject". mymedaproject is the name of my project and is not a python library which is why I am confused. I followed the instructions from this recipe to get to this point:
http://pyramid-cookbook.readthedocs.org/en/latest/deployment/heroku.html
Any ideas?
May be you forgot to put your python project mymedaproject in development mode. What follows is the relevant part of the cookbook recipe.
Create a Procfile
$ echo "web: ./run" > Procfile
Create run with the following:
#!/bin/bash
python setup.py develop
python runapp.py
The first line puts your python project in development mode and enables Paste to load it using your INI file. Make sure Procfile, run, runapp.py and setup.py are in same directory.
References
Getting Started with Python on Heroku
Process Types and the Procfile
Optimization
running a script using a Procfile should work without making it executable
$ echo "web: sh ./run" > Procfile
Check your .gitignore file that it isn't blocking any egg or egg-info information.
If it is, Heroku won't be receiving the egg for your application.

Running a python script on my hosting

I am a newbie to web development and Python. Since I dont have the vocabulary to ask the exact question, here is a summary of what need to do:
I have a small test python cgi script, which i have uploaded to /home/username/pyscripts which is above the /home/username/domain.com
I need a link I can type in the URL bar, which will lead to the script being executed and the content displayed in the browser.
Can someone tell me If i need to create an html file, and if yes how to get it to point to the python script The domain folder has wordpress installed. My hosting is dreamhost shared hosting
The script is there below:
#! /usr/bin/python
print 'Content-type: text/html'
print ''
print 'Hello, World!
Heroku is a good place to host and python scripts.
Pre-req
pythonscripts.py
procfile
requirements.txt
and After add, commit and push the scripts to heroku app. Just run the following command on terminal to run the scripts.
heroku run python your_scripts.py
More if you want to run this scripts on a schedule timing. then heroku provides lots of adds-on. just search it on heroku
Usually you'd need to put your python script under the /home/username/bin/ folder. I'm not sure if your particular webhost actually allows you to run your Python script outside of the /bin folder (normally this is not the case), but if yes then you can substitute the /pyscripts folder.
The URL would look something like this: www.domain.com/bin/mypythonscript.py
Or with the pyscripts folder (if possible with your webhost): www.domain.com/pyscripts/mypythonscript.py
You don't need to create an HTML file as the first content line that you print in your Python script is telling the user's browser to display the output of the script like an HTML file. You simply type the URL to your python script into your browser and then the server runs the script and outputs it as a text/HTML file, which your browser then reads and displays.
Also, don't forget - you need to grant execute/read/write permission to your Python script file after you upload it to the correct folder on your webhost server or it won't run at all. Usually this is done through your upload utility like Filezilla or using a shell command like chmod.
Well dream host support python. Check if they are providing shell access deployment. All you need is create .py file and run it.
Then consider to use Django or Jinja2 like framwork. Its easy for creating web application

Categories

Resources