I'm trying to create a basic web app using Flask and Google Datastore to make myself to Google Cloud. Though, when I deploy my app, I get an Error 500, the details being that Python can't import Datastore : ImportError: No module named cloud.
Here is my app.yaml:
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: .*
script: main.app
libraries:
- name: jinja2
version: "2.6"
- name: markupsafe
version: "0.15"
- name: flask
version: 0.12
My main.py starts like follows:
from __future__ import absolute_import
# Standard imports
import time
import logging
import json
import threading
# Flask framework
from flask import request
from flask import Flask
# Google Cloud features
from google.cloud import datastore
# the following replaces requests
from google.appengine.api import urlfetch
Finally, my requirements.txt is the following:
Flask
google-cloud
click
When I deploy my app (using gcloud app deploy) and get to my site, I get my error 500.
I don't understand why I can't use from google.cloud import datastore since it's what Google does in their tutorial... I must be missing something but I can't find what.
Any help would be appreciated.
From Installing the client library:
pip install --upgrade google-cloud-datastore
The client library you need (to match your import statement) is google-cloud-datastore, but you don't have that listed in your requirements.txt file.
Side note: your app.yaml file indicates your app is a standard env GAE app one, for which you have the optimized Google Datastore NDB Client Library library available, already included in your SDK (if you don't have specific reasons for choosing the generic one instead).
You do not specify env: flex so you are using Standard Environment. Here it is described for flex yaml and here it doesn’t appear for standard yaml.
This is important because google-cloud is not supported for Standard Environment. google-cloud’s repository:
These libraries currently do not run on Google App Engine Standard
Link mentioned by Dan Cornilescu about the NDB Client is an oficial solution for standard environment and few examples can be found in the oficial documentation:
https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/appengine/standard/ndb and https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/appengine/standard/multitenancy
Related
When deploying a flask application on heroku im getting the error above. The problem on heroku is that it installs dependencies and Iam not able to overwrite them then, or?
On my local server i just went to flask_uploads.py and change the imports to:
from werkzeug.utils import secure_filename
from werkzeug.datastructures import FileStorage
and this works fine.
but when deploying the flask app to heroku, how can I change the the content of flask_uploads.py after it had been installed?
flask-uploads is no longer properly maintained and has not released a fix to the updated Werkzeug API change, thus you see this error.
Just swap flask-uploads with flask-reuoloaded in your dependency list, eg requirements.txt or similar. You don't have to change your imports!
See https://github.com/jugmac00/flask-reuploaded
I am using google-auth to allow firebase authentication in my GAE project.
Everything works fine when I run the code locally using dev_appserver.py or when I deploy it to google app engine.
But I get this ImportError exceptions when I try to use Django's manage.py script to create/run migrations.
ImportError: Could not import 'firebase.authentication.FirebaseAuthentication' for API setting 'DEFAULT_AUTHENTICATION_CLASSES'. ImportError: No module named auth.transport.requests.
The google-auth module is installed under lib directory and has this structure:
- lib
- google
- auth
- oauth2
These import cause the ImportErrors:
import google.auth.transport.requests
from google.oauth2 import id_token
My guess is that there might be naming conflicts as other imports work fine.
Please help!
If you want to use 3rd party libraries that are not included in this list, then you'll have to add them manually since you have done that by adding lib folder and including all the package folder follow these steps.
Create your_app_directory/appengine_config.py file.
Add these following lines inside that file
from google.appengine.ext import vendor
vendor.add('lib')
This should solve the import error problem.
I'm attempting to setup firebase-admin with google-app-engine standard python. My dev environment is windows and I've followed the library setup as indicated in how to install 3rd party libraries. The firebase website indicates that firebase-admin has been tested on app engine, but there are no instructions or indication as to whether it was tested in standard, flexible or both. I've started with the most basic example and just tried the first import from the firebase generic documentation.
import webapp2
import firebase_admin
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.write('Hello, World!')
app = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
The result is
ImportError: The requests library is not installed, please install the
requests package to use the requests transport.
The requests library in lib during the install of firebase-admin so I'm not sure why I get this message. If I add import requests immediately before import firebase_admin I will instead get this message.
ImportError: No module named _winreg
I'd like to use firebase-admin if at all possible so if anyone is familiar with this situation and how to resolve it please let me know. Also, I am not interested in using the flexible environment, this is a question for the standard environment only.
-Install necessary modules under lib;
pip install -t lib/ firebase-admin
pip install -t lib/ requests-toolbelt
-you can delete the .pyc files as they are just the precompiled versions of the .py files that are also there (and will be regenerated when .py is executed).
-add below code in added the appengine_config.py;
from google.appengine.ext import vendor
vendor.add('lib')
import requests
import requests_toolbelt.adapters.appengine
requests_toolbelt.adapters.appengine.monkeypatch()
import platform
def patch(module):
def decorate(func):
setattr(module, func.func_name, func)
return func
return decorate
#patch(platform)
def platform():
return 'AppEngine'
see https://groups.google.com/forum/#!topic/firebase-talk/FzEG2U6SRN8
I'm running Django locally through Google App Engine's dev_appserver.py ./ and when I add this one line to my script:
from google.appengine.ext import deferred
I get the error: ImportError: No module named webapp2 from the deferred module.
I tried adding this to my libraries in app.yaml:
- name: webapp2
version: latest
But that doesn't work either. I feel like it doesn't make sense to use webapp2 when I'm running Django... Is it not possible to use deferred with Django on Google App Engine?
I'm trying to queue Django's send_mail() for a contact form, and I don't want the User to have to wait for it to be sent.
Not sure if this helps, but here's part of my Python Path which is displayed with the import error:
'/usr/local/google-cloud-sdk/platform/lib/MySQLdb-1.2.5',
'/usr/local/google-cloud-sdk/platform/lib/django-1.4',
'/usr/local/google-cloud-sdk/platform/lib/webapp2-2.5.2',
'/usr/local/google-cloud-sdk/platform/lib/protorpc-1.0',
'/usr/local/google-cloud-sdk/platform/lib/webob-1.1.1',
'/usr/local/google-cloud-sdk/platform/lib/yaml-3.10'
As you can see, it is loading webapp2 into the python path.
I'm running into this weird error with a Cloud Endpoints app that I'm just starting to write. I'm not sure if Google changed their libraries or not, but I think this should work?
In my app.yaml I've got...
libraries:
- name: webapp2
version: "latest"
- name: endpoints
version: "latest"
And then in my main.py I call:
import endpoints
Result:
ImportError: No module named endpoints
Why would app engine be telling me that endpoints doesn't exist? I can see the endpoints folder in the directory itself...
I got the same thing on a fresh install of the SDK (previously worked).
You need to explicitly add the relevant GAE libraries to your PYTHONPATH.
For example if you're using virtualenvwrapper (you should be):
$ add2virtualenv /path/to/google-cloud-sdk/platform/google_appengine/lib/endpoints-1.0
$ add2virtualenv /path/to/google-cloud-sdk/platform/google_appengine/lib/protorpc-1.0