How to check if there are errors in python - python

While using Google App Engine if there is an error in python the result is a blank page. It is difficult to debug python since you don't get line number on which there is error. It is extremely frustrating when you get blank page because of indentation error. Is there any way to execute python google app engine script in python interpreter so i get python error there itself.

If you are using the App Engine Launcher then by clicking on the Logs you can see all the logs and errors.
An alternative way is to start the development server via the command line (as it's already mentioned) and you will see all the logs there, which makes it much easier to work with because the Logs windows is not that flexible.

You can try to use the The Python Development Server.
dev_appserver.py myapp
Here is the documentation https://developers.google.com/appengine/docs/python/tools/devserver?hl=es

Related

Is it possible to have a Heroku app that is just a python console?

I have been writing a pretty simple python quizz system (called game.py) and I am working to deploy it on heroku. The app functions exclusively within the confines of a python console, with no interface of any kind but that provided by a terminal.
As such, I would like to be able to have the application on Heroku simply be akin to what you obtain with a one-off dyno, available on the dashboard (or in a terminal with the CLI) with:
heroku run python game.py
The application works perfectly well in it's deployed form (exclusively from the Heroku git) and locally, but in order for the app to be available to a larger public, I would need to have such a console appear on the "https://[appname].herokuapp.com/" URL that you are given on deployment of the app.
Naively, I would think this to be unspeakably simple to pull off, but I have yet to find a way to do it.
The only reasonable thing I have found would have been to create a Procfile, but lacking any documentation on the commands available, I only have been able to try variations of:
web: run python game.py
Which doesn't create a web console. And:
web: bash
Which simply crash with error code h10, with no other information given.
Any help, any suggestion, any workaround you can think of would be extremely appreciated.

View logging info in log console

I've added some logging.debug statements to get some more information about where I'm having a problem setting up an endpoint, but I have not been able to get the dev server to show the logs.
I'm trying to update the application settings from the Launcher as mentioned in one of the answers for this question. Unfortunately, it doesn't seem like the Launcher is actually adding the extra command line flag I'm including, --log_level=debug, because the log console is not showing any additional information when I test the endpoints on my dev server. I've tried adding the extra command line flag both before and after using Launcher to run the app, and access the dev server.
I also saw this video on YouTube. I'm running Windows (he's on Mac in the video), but I tried what he does just in case, by adding --debug, but that didn't do anything either.
Initially, I was trying to download the logs with the help of questions like this one, but it seems my command line skills are lacking, because I couldn't get that to work and it kept insisting that I wasn't specifying the directory, which is why I'm trying to do this through the Launcher.
The GAE docs said the regular Python logging module works, so I'm just using that. I'll be happy to provide more information if necessary.

GAE - Online admin console

Is there some way I can run custom python code on my google appengine app online? Is there a python console somewhere that I can use? I've seen vague references here and there, but nothing concrete.
Check out these previous answers on how to enable the interactive console (that you can use on the local dev appserver) on your deployed application.
You can use remote shell, that is on your app engine sdk.
For example
~/bin/google_appengine/remote_api_shell.py -s your-app-identifier.appspot.com s~your-app-identifier
When you are inside the shell, you will have the db module enabled. in order to use your models, you will have to import them.

Python 2.7.2 and Google App Engine SDK 1.6.1 on Win 7 Home Premium not working

I have installed Python 2.7.2 (Win7 32-bit) and Google App Engine SDK 1.6.1 for Win7 on a 64-bit system running Win7 Home Premium. Default folder locations for both Python and GAE. When I try to run the helloworld project as described in the Google Python Getting Started doc, the Launcher's "browse" button never becomes active. The GAE SDK is supposed to do fine with Python 2.7.
Is there a complete listing anywhere of environment variables needed for this setup to work? So far, all posts I have seen are from users who have gotten well past this absolutely basic step.
The Google docs for setting up GAE with Python 2.7 have some issues. If you are trying to launch the basic "hello world" app through the GUI App Engine interface, after following the instructions, you are probably seeing red text and all the buttons are grayed out?
If so, it is because there are errors within your helloworld.py program - this is where the Google instructions failed.
The import statement they have in the instructions:
import webapp2
This fails, it needs to point to the local instance of GAE's webapp. Also, their Python 2.7 program is incomplete. If you look at the Python 2.5 example, you will see the complete program (you may need to modify webapp --> webapp2 for Python 2.7?):
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class MainPage(webapp.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello, webapp World!')
application = webapp.WSGIApplication(
[('/', MainPage)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
Last thing, the YAML file in the Google instructions refer to "helloworld.app" - I can't confirm this, but I think it needs to be "helloworld.py" ?? I don't know, I may be wrong.
A couple months have gone by since you posted the question, if you found out any details, please feel free to update this question.
I was facing the same issue, browse button was disabled. I ran dev_appserver.py helloworld command at command prompt and then opened localhost:8080 in my browser the hello world program ran successfully.
I compared the helloworld example to the guestbook demo and found that the application element was key. I added the line at the top of the app.yaml file "application: helloworld" and the helloworld example started working in the Google App Engine (GAE). Note that the 'application' element is supposed to be optional as defined in the app.yaml reference. It looks like it is optional if you use the command line, and it is not optional if you use GAE.
Do you see anything in the GAE SDK logs?
Which browser are you using? What is your default browser?
The default security settings in IE require you to enable intranet access.
I recently had to rebuild my Win7 dev box. Chrome was my default browser. When I installed GAE SDK v1.6.1 I had a similar problem to what you describe.
I checked logs and fiddled with the browser configuration to resolve it.
My recollection was that once I made IE 9 my default browser again, i saw the intranet security error. After enabling access to intranet sites like localhost:8080, things started working OK, but start-up was sometimes slow. Then I made Chrome my default browser again and the start-up became a bit faster and more reliable.
I am quite sure that is because you had changed the encode from ANSI to another type (such as UTF-8) on app.yaml,
change it back to ANSI, then you can run the project on google app engine launcher.
BTW, the helloworld tutorial on google has no problem.
I had a similar issue; it turned out my problem was not due to environment variables.
Debugging GAE:
First off let me say that if you are having problems with GAE, I would strongly recommend launching using the CLI, google_appengine/dev_appserver.py. There is a large stack trace of the reason GAE is failing (instead of simply a red link in the GAE Launcher GUI) that will point you in the right direction.
Hidden bad characters:
When copying the text from google's "hello world" tutorial, there was an invisible hidden character at the start of my YAML file (I found it using kdiff, a diff tool). After deleting this character, my app launched (and showed up as not red in the GAE Launcher GUI).
Environment Variables:
As to your original question, the only relevant environment variable I have set is my PATH variable, where I have appended the folder of my python executable (in my case C:\Python27) so that I can run python files without specifying the full path to Python. Let me repeat, however, that I do not believe this is the cause of your problem, but you can more directly confirm this using the CLI.
Like pghprogrammer4 above, I solved this problem by removing bad characters in my files. They were invisible in my regular text editor (sublime text 2) but I found them with that editor's hex editor. I knew what to look for, because I noticed a space at the start of my Guestbook app (a few tutorials in). So I looked at the debug in Chrome, and it showed the character Zero Width Space. The Unicode site has the hexadecimal value of this character so I searched for that (didn't need to search far; it was the first three bytes of the file), and removed it. Thankfully Sublime Text 2 has a hexadecimal mode, but you could use any hex editor to find and remove the bad characters.
I am certain that this is due to a very particular method of copying and pasting from the Google tutorial site. It didn't happen to me in the Hello World example because I typed that out by hand. Then it appeared in one of my files, causing the CSS not to load. After that it caused the Google App Engine Launcher to think of my project as having missing files (turning up red in the launcher). I reverted to a working version (just by undoing in the text editor), and copied each set of new commands into the file from the tutorial, hoping to catch the bit of script that was doing me over. But when I got to the end it was all working. I SURMISE that this error is introduced when you copy and paste AN ENTIRE box of text from the Google App Engine tutorial site and insert it into one of your files. I suspect that ZWSP character exists on that site as the first character in the code boxes or something, but it's late and I'm not going to look into it further for now.
I guess you should just type out the tutorials - it's probably a better way to learn anyway.
I did two changes together -
1. added the line at the top of app.yaml file "application:helloworld"
2. changed the last line in app.yaml "script: helloworld.app" to "script: helloworld.py"
my GAE started working. However to islolate the issue I 'undid' both changes, it turns out that the the 2nd change - changing helloworld.app to helloworld.py did the magic

Calling an executable from within Python / Django web application running on IIS

I have a Python / Django application which is supposed to call an external windows binary and get its output at some point. And it does so when tested via 'python manage.py shell'.
But when it is run from within the web browser, which is served by IIS, the external application is not executed.
Is IIS blocking something on the way? Can this be avoided?
Any help is much appreciated.
oMat
Might be a permissions issue. when you run from the shell, you're using the user that run the python manage.py shell command. When serving requests from the IIS you're using its user (IUSR or something like that). Try giving execution permission on the executable file to the Everyone group just to see if it helps.

Categories

Resources