View logging info in log console - python

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.

Related

How can I get the token-sheets.pickle and token-drive.pickle files to use ezsheets for Google Sheets?

I am trying to set up ezsheets for the use with Google Sheets. I followed the instructions from here https://ezsheets.readthedocs.io/en/latest/ and here https://automatetheboringstuff.com/2e/chapter14/
The set up process works quite differently on my computer: Somehow I could download the credentials-sheets.json. I need to download the token-sheets.pickle and token-drive.pickle files. When I run import ezsheets, no browser window is opended as described in the set up instructions. Nothing happens.
Is there another way to download both files?
I followed the steps you referenced and managed to generate the files, but I also encountered the same issue before figuring out the cause. The problem is that there are a few possible causes and the script silently fails without telling you exactly what happened.
Here are a few suggestions:
First off you need to configure your OAuth Consent Screen. You won't be able to create the credentials without it.
Make sure that you have the right credentials file. To generate it you have to go to the Credentials page in the Cloud Console. The docs say that you need an OAuth Client ID. Make sure that you have chosen the correct app at the top.
Then you will be prompted to choose an application type. According to the docs you shared the type should be "Other", but this is no longer available so "Desktop app" is the best equivalent if you're just running a local script.
After that you can just choose a name and create the credentials. You will be prompted to download the file afterwards.
Check that the credentials-sheets.json file has that exact name.
Make sure that the credentials-sheets.json file is located in the same directory where you're running your python script file or console commands.
Check that you've enabled both the Sheets and Drive API in your GCP Project.
Python will try to setup a temporary server on http://localhost:8080/ to retrieve the pickle files. If another application is using port 8080 then it will also fail. In my case a previously failed Python script was hanging on to that port.
To find and close the processes using port 8080 you can refer to this answer for Linux/Mac or this other answer for Windows. Just make sure that the process is not something you're currently using.
I just used the single import ezsheets command to get the files so after getting the token-sheets.pickle I had to run it again to get the token-drive.pickle, but after that the library should detect that you already have the files.

Getting push to deploy to work, configuring "release pipeline"

So since last week suddenly git push origin master doesn't work anymore to "push to deploy". It sure pushes the sources to remote repository at Google, and the code is there but it never deploys. Read about it here: GAE: Trouble with push to deploy
It seems things are changing over at Google and this week there is new stuff in the Google Developer Console, in the "Cloud Development/Releases" section; "Configure Release Pipeline"
There are three settings: the pipeline name, pipeline tasks, and then an optional setting to have deploy notifications sent by email.
I just enter a random name like "mydevpipeline", select "Deploy source only", and check the email box. But I just get this error: "Failed to create the pipeline.". I also tried unchecking the email box, still same error. Tried it over and over.
No where to go from there...
Anyone been able to create this pipeline and get it all working?
It seems that this pipeline configuration must go through in order for push to deploy from now. I haven't seen any news or notification about this change...
Fwiw, the documentation https://developers.google.com/appengine/docs/push-to-deploy states nothing about pipelines. It's just outdated I guess.
Update:
What do you know... I went on trying to configure this pipeline on the live GAE project (the one described above is the dev GAE project I'm using)... and it worked. I could configure a pipeline ok. After that, I could once more push-to-deploy, alas only on the live version so far. I might try creating a new dev project, it seems existing projects "break" from time to time... I have had similar problems before and creating a new project DOES solve things from time to time.....
Google App Engine pipelines do not like .gitignore file. Try if it works without that file. It fixed the problem for me.
It took me a long time to get this working for PHP, after a lot of communication with Google it was finally revealed to me that in your app.yaml file you need to have a line that reads:
threadsafe: false
In order for the pipeline to successfully pick up and deploy your git push (I use sourcetree, but command line git has the same end result) that line must be present. If it's omitted or set to true the pipeline won't be able to deploy it.
I wanted to throw this answer on here in case anyone stumbled on this thread looking for help. One of my projects has "randomly broken" and after 3 months of successfully using my release pipeline for multiple commits per day it suddenly no longer deploys when I push. Ultimately giving the extremely helpful error message of "Unable to get deployment status" - and now none of my changes can be applied to the live site. Copying the entire source code, changing the app name, and pushing to a new GAE project with release pipeline works fine, but I need the original site to start working again.

How to check if there are errors in 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

Google App Engine Launcher fails to start

I'm having a problem with the Google App Engine Launcher (the GUI thingy).
I have it installed on two PCs. Both PCs have Python. On both, the launcher ran (the first time) successfully after the installation. On both, at first it failed to deploy an app I was feeding to it, apparently due to being unable to detect Python.
On my home PC, I opened preferences and manually set the path to Python. After that, the app was deployed, and the launcher has been working fine since then, never failing to start. On my work PC, I missed the opportunity to set the Python path, and the launcher fails to start. The log tells me: ConfigParser.NoOptionError: No option 'name' in section: '0'. I suspect this could be due to the missing Python variable.
Unfortunately there doesn't appear to be any kind of config file that contains this setting for GAE. Searching the Windows registry has turned up nothing useful either. I've tried searching the site for problems with the launcher, or how to set the Python path without using GUI, but only found information on problems with apps, not the launcher itself.
A quick google suggests:
try to find and delete file google_appengine_projects.ini
here
or
in Google folder , you have google_appengine_projects.ini file.
Delete it's [0] section.
Or just uninstall and reinstall the launcher.
If still nothing, download an IDE instead - I use pycharm. It's not free (there are free ones out there) but it does manage the launcher for you.

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

Categories

Resources