Google app engine and prediction API (error import) - google-app-engine

Please help me to solve this error? I'm doing this exercise on app engine (https://developers.google.com/appengine/articles/prediction_service_accounts) , but I'm stuck in step 6.2 because I raise this error(When I run the deploy operation, it is successful step 6.1):
: No module named appengine
Traceback (most recent call last):
File "/base/data/home/apps/s~01prediction/1.367567721220366691/main.py", line 29, in
from oauth2client.appengine import AppAssertionCredentials
The error in line 29 :
from oauth2client.appengine import AppAssertionCredentials

Did you run step 3.2? That should have copied some folders into prediction-demo-skeleton. You should have a folder called oauth2client inside prediction-demo-skeleton. Take a look at the folders that are inside prediction-demo-full.
ps: a good practice before deploying is to run your app using the devappserver.

The Google API Python Client now has a pre-packaged ZIP containing all dependencies that might make installation easier. See:
https://code.google.com/p/google-api-python-client/downloads/list
Select google-api-python-client-gae-1.1.zip for download. Unzip this file inside of your AppEngine app directory.
Along the lines of Sebastian's suggestion it generally is a good idea to test locally using the devappserver. In this case you should be able to get past the import issue, however AppAssertionCredentials won't actually be able to generate any access tokens until it is deployed into a production environment, so it will be of limited use for you.

Related

peewee problem: No module named 'playhouse' when deploying using AWS Chalice

I am working on an AWS Chalice project, and I chose peewee as the ORM for the DB we have.
When I run things locally with chalice local I can run my api with no problem, I'm able to CRUD normally.
When I deploy my microservice using chalice deploy and I go test it out on the live url, I encounter an error 500. When looking into the logs I see this message multiple times:
Traceback (most recent call last):
2023-01-03 22:39:57.665000 s98frt [ERROR] Runtime.ImportModuleError: Unable to import module 'app': No module named 'playhouse'
I cannot do poetry add playhouse, because I get the following error: Could not find a matching version of package playhouse. Strange because playhouse comes with peewee.
What can you suggest me to do to fix this?
Thank you so much

No module named 'google.appengine' from within Cloud Shell

I'm testing Google App Engine and trying to run a simple function to upload files to either the Blobstore or Cloud Storage. I'm typing the Python code directly in the Cloud Shell of my instance. The code is failing when I call:
from google.appengine.ext import blobstore
I get the error code:
Traceback (most recent call last):
File "upload_test.py", line 1, in <module>
from google.appengine.api import users
ImportError: No module named 'google.appengine'
Even though the documentation says that: You can use Google Cloud Shell, which comes with git and Cloud SDK already installed, I've tried installing a bunch of libraries:
gcloud components install app-engine-python
pip install google-cloud-datastore
pip install google-cloud-storage
pip install --upgrade google-api-python-client
I'm still getting the same error. How can I get the appengine library to work? Alternatively, is this the wrong method for creating an app that allows the user to upload files?
The google.appengine module is baked into the first-generation Python (2.7) runtime. It's not available to install via pip, in the second-generation (3.7) runtime, or in Cloud Shell.
The only way to use it is by writing and deploying a first-generation App Engine app.
Thanks #Dustin Ingram
I found the answer in this page.
The current "correct" way of uploading to Cloud Storage is to use google.cloud.storage. The tutorial I linked above explains how to implement it.
The impression I have, however, is that this uses twice the bandwidth as the solution via google.appengine. Originally, the front-end would receive an upload url and send the file directly to the Blobstore (or to Cloud Storage). Now the application uploads to the back-end which, in turn, uploads to Cloud Storage.
I'm not too worried, as I will not be dealing with excessively large files, but it seems strange that the ability to upload directly has been discontinued.
In any case, my problem has been solved.

ImportError: No module named google.appengine.ext.webapp.mail_handlers

I'm trying to get google app engine to work on my Raspberry Pi. I keep getting this error.
Traceback (most recent call last):
File "main.py", line 26, in <module>
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler
ImportError: No module named google.appengine.ext.webapp.mail_handlers
I downloaded google app engine and then ran these commands:
unzip google_appengine_1.9.40.zip
export PATH=$PATH:/home/pi/google_appengine/
The most trivial solution for such errors is to import the required package into you project directory. but to be honest it is not the best way to resolve this one. you may use Google App Engine SDK which will take care of all that headache, or there are another way you can follow:
Create a folder into your project directory and call it lib
Add all required packages into this folder.
Create a .py file and name it appengine_config.py
Add the below code snippets into this file:
import sys
import os.path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'lib'))
appengine_config.py gets loaded every time a new instance is started, and should take care of your modules importing.
Regards.
It appears you're trying to directly execute your main.py as a standalone application, which is not how GAE app code works.
You're supposed to get the development server (from the SDK you downloaded) to execute your app code on your development machine (on GAE it's the GAE infra doing that). See Using the Local Development Server.

Running GAE GCS on PyCharm under OS X, runtime error "No module named cloudstorage"

I am trying to add Google Cloud Storage functionality to a Python GAE app that is already running with significant functionality. I work entirely within PyCharm on my development computer, which is a Mac running OS X 10.9.5.
I have created a new Python module that contains this statement:
import cloudstorage as gcs
as shown in the sample code at https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/getstarted
When I first added that line, PyCharm said "No module named cloudstorage" in the editor.
I then followed both the "pip" and the "svn" instructions at https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/download
to download the GCS Client Library.
In trying to follow those instructions, taking into account my prior experience with this programming environment, I actually tried using "pip" three times:
Once without the "-t" option, since I've never needed that option with "pip" before
Once using the "-t" option to specify my application directory's "lib" subdirectory
Once using:
pip install GoogleAppEngineCloudStorageClient -t /Applications/GoogleAppEngineLauncher.app//Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib, since I wasn't sure what the instructions meant by "<your_app_directory/lib>"
As mentioned, I also executed the "svn" command. Then, as mentioned in install python google cloud storage client on Ubuntu 14.04, I ran "cd gcs-client/src" and "sudo python setup.py install". I ran these commands in my user root directory.
After each of those successful but different installations of the GCS Client Library, I looked at the PyCharm editor window for my module, and it always had the same "No module named cloudstorage" error. But as an experiment, I would also try restarting PyCharm, and also try running my app.
At some point, the editor window stopped showing the error. It was not immediately after one of those steps above, but after I would go away to read various webpages and then come back to look at the error again. I don't know which of the installations was the one that got rid of the error message in the PyCharm editor.
In any case, whenever I try to run the app (again, inside PyCharm), I always get the runtime error "ImportError: No module named cloudstorage" on the same import statement.
The Run/Debug Configuration page for this app has both "Add content roots to PYTHONPATH" and "Add source roots to PYTHONPATH" checked.
Of course the main help I want is how to get past the "No module named cloudstorage" runtime error, even though the import statement no longer shows an error.
I think I also have as many as three spurious versions of the GCS Client Library. I'm much more concerned with getting past "Module not found", since it's a show-stopper, but if you have any idea how I can delete the spurious versions so that they're not just lying around, I'd be most grateful for that help as well.
If the "cloudstorage" directory is at <app>/lib/cloudstorage, then the import statement has to specify "lib":
import lib.cloudstorage
In my case, it's:
import lib.cloudstorage as gcs
By the way, the <app>/lib/GoogleAppEngineCloudStorageClient-1.9.5.0-py2.7.egg-info directory does not seem to be needed and can be deleted.
Actually, you also need to
touch __init__.py
in the lib directory. This will make the cloudstorage module visible to the "import lib.cloudstorage" command.
Dear Google: The distributions should include this file (or the procedure should account for it), and the demo script should be changed to reflect the expected usage. But more importantly why are you distributing/PROLIFERATING library code like this??!!! Why is this not distributed via gcloud? How am I ever going to pick up a patch for this library?
The accepted answer's solution
import lib.module_name
definitely can solve the problem. But I don't like add lib in front of every single module and happened to see how Google suggest import third party libs like this.
appengine will automatically run a file called appengine_config.py. So you can create such a file and put
from google.appengine.ext import vendor
vendor.add('lib')
inside that file. This will help you tell appengine to find dependencies in that folder, so you can simply write
import cloudstorage as gcs
I solve the missing module issue by adding the following to my main application file (main.py):
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), "lib"))
I think this is the way Guido intended. Now my code simply says import cloudstorage as gcs. None of the lib.cloudstorage or lib/__init__.py business.
From
https://stackoverflow.com/a/37645984/1740008

My Google App Engine appspot URL wont work

I recently created my Google App Engine account, and uploaded my application, and have an instance of said app running.
I can access my app via localhost:8080 but when I try to use myappid.appspot.com I get a 500 Server Error (Of course I replace "myappid" with my apps name). This is what it says:
"Error: Server Error
The server encountered an error and could not complete your request.
If the problem persists, please report your problem and mention this error message and the query that caused it."
Can anyone help me get the URL working? I need my team to be able to access this app from anywhere. I have no idea what could be wrong with it, I am very new to GAE. After a lot of searching all I find is people saying their appspot URL works, and want other options. But I just want my appspot URL to work first!
Some more info:
This is a Python app, using the GAE Python SDK, I am running Windows 7, and using the GAE Launcher GUI to deploy and run the app.
Thanks in advance!
EDIT: Here is the error in my Log:
: No module named flask Traceback (most recent call last): File "/base/data/home/apps/s~luxtestapp/1.362824400913245138/bootstrap.py", line 19, in from app import create_app File "/base/data/home/apps/s~luxtestapp/1.362824400913245138/app/init.py", line 10, in from flask import Flask
Apparently the app uses Flask instead of Webbapp2. Honestly I'm not too sure about it all, because this is a pre-built app that I downloaded and deployed. I didn't write it.
In the control panel for your app on appspot go to the log section.
Appengine
The see what the latest entry says. Filter to "error".
Also when you create your app (python webapp2 example) turn debugging on:
app = webapp2.WSGIApplication([
('/', MainHandler)],
debug=True)
You'll get a much more informative error screen then instead of '500'.
You need to copy the flask folder to your project folder. In general every package not supported by GAE (see list of supported libraries), must be present in the project folder.
Try setting the environment variables before/after deploy. Go to the local project folder, open bash the paste this commands: ps: Ignore the $ sign
$ set HTTP_PROXY=http://cache.example.com:3128
$ set HTTPS_PROXY=http://cache.example.com:3128
check this link out for help: cloud.google.com/appengine/docs/python/tools/uploadinganapp

Resources