I have a GAE application that I want to integrate with Sendgrid. I've followed the instructions (https://cloud.google.com/appengine/docs/python/mail/sendgrid) on how to install Sendgrid and everything works fine in my local dev environment.
However, when I push my application to GAE and run it, I immediately receive the following 500 Server Error:
Error: Server Error
The server encountered an error and could not complete your request.
Please try again in 30 seconds.
Even with debug on, that's all I get. But digging into the logs at GAE I can see the source of the problem:
Traceback (most recent call last): File
"/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py",
line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) File
"/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py",
line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler) File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py",
line 85, in LoadObject
obj = ____import____(path[0]) File "/base/data/home/apps/....wsgi_app.py",
line 16, in
import sendgrid File "/base/data/home/apps/..../sendgrid/____init____.py",
line 7, in
from .client import SendGridAPIClient File "/base/data/home/apps/..../sendgrid/client.py",
line 1, in
import python_http_client ImportError: No module named python_http_client
So I went into sendgrid/client.py and commented out the following line of code...
import python_http_client
Once I do that, I can run my app without receiving the 500 Server Error but the test email I tried to send wasn't delivered (although I didn't receive any error messages when trying to initiate it).
It doesn't seem right that I need to comment out a line of the Sendgrid code to make the import work and I can't figure out why others that are running Sendgrid with Python and GAE aren't having the same problem. Any thoughts would be appreciated. Thanks.
sendgrid does need python_http_client, which Sendgrid itself maintains at https://github.com/sendgrid/python-http-client -- just copy the few files in directory https://github.com/sendgrid/python-http-client/tree/master/python_http_client to a directory named python_http_client, making the latter a sibling of the sendgrid directory. I'm not sure why the online docs don't mention that -- I'll work to get it fixed, but meanwhile I hope this workaround lets you get started.
Related
I am attempting to use the Google Cloud Datastore, but importing google.cloud.datastore gives an ImportError:
ERROR 2018-03-13 19:28:29,013 wsgi.py:263]
Traceback (most recent call last):
File "/home/<user>/Software/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/home/<user>/Software/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/home/<user>/Software/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/home/<user>/Projects/<my_project>/main.py", line 1, in <module>
from my_project import app
File "/home/<user>/Projects/<my_project>/<my_project>/__init__.py", line 2, in <module>
from my_project.submit.controllers import submit
File "/home/<user>/Projects/<my_project>/<my_project>/submit/controllers.py", line 6, in <module>
from . import model_datastore
File "/home/<user>/Projects/<my_project>/<my_project>/submit/model_datastore.py", line 2, in <module>
from google.cloud import datastore
File "/home/<user>/Projects/<my_project>/env/local/lib/python2.7/site-packages/google/cloud/datastore/__init__.py", line 57, in <module>
from pkg_resources import get_distribution
ImportError: No module named pkg_resources
I am on Linux Mint attempting to run a Google App Engine local dev server.
I am using a virtual environment. Both setuptools and pkg_resources are installed and updated in the virtual environment. When I enter the python cmd line interpreter from the virtual env and import pkg_resources, it works fine. When I run the google app engine dev server by doing dev_appserver app.yaml, everything works fine until I access the page that activates the handler that imports datastore, then I get this error.
None of the other similar posts about 'pkg_resources` import error were helpful.
If there is any other info I can provide that would help, please let me know. Thanks!
In the standard environment you need to install all your dependencies inside your application. See Using third-party libraries.
Whatever you have installed in the local environment (virtual or not) doesn't matter, GAE doesn't know how to use those and your app might not work properly locally and definitely won't work when deployed on GAE.
You traceback indicates that you're loading the datastore library from your virtual env, not from your app, which is most likely why it doesn't work:
.../env/local/lib/python2.7/site-packages/google/cloud/datastore/__init__.py
You need to fix your app dependency installation.
This discussion might be of interest as well: No module named warnings when starting GAE inside virtualenv locally
I have an App Engine application which breaks the moment I do
import apache_beam
I can confirm the dependencies are installed within the virtual environment the app runs in. Judging by the stack trace below it looks like it's trying to access /dev/null for some reason and it fails to.
INFO 2017-08-13 13:03:37,980 stubs.py:50] Sandbox prevented access to file "/home/raul/Downloads/google-cloud-sdk"
INFO 2017-08-13 13:03:37,980 stubs.py:51] If it is a static file, check that `application_readable: true` is set in your app.yaml
INFO 2017-08-13 13:03:37,980 stubs.py:50] Sandbox prevented access to file "/home/raul/Downloads/google-cloud-sdk/platform"
INFO 2017-08-13 13:03:37,980 stubs.py:51] If it is a static file, check that `application_readable: true` is set in your app.yaml
INFO 2017-08-13 13:03:38,260 stubs.py:50] Sandbox prevented access to file "/dev/null"
INFO 2017-08-13 13:03:38,260 stubs.py:51] If it is a static file, check that `application_readable: true` is set in your app.yaml
ERROR 2017-08-13 13:03:38,261 wsgi.py:263]
Traceback (most recent call last):
File "/home/raul/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/home/raul/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/home/raul/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/home/raul/Documents/football/main.py", line 7, in <module>
import apache_beam
File "/home/raul/Documents/football/env/lib/python2.7/site-packages/apache_beam/__init__.py", line 75, in <module>
import apache_beam.internal.pickler
File "/home/raul/Documents/football/env/lib/python2.7/site-packages/apache_beam/internal/pickler.py", line 38, in <module>
import dill
File "/home/raul/Documents/football/env/lib/python2.7/site-packages/dill/__init__.py", line 27, in <module>
from .dill import dump, dumps, load, loads, dump_session, load_session, \
File "/home/raul/Documents/football/env/lib/python2.7/site-packages/dill/dill.py", line 165, in <module>
FileType = type(open(os.devnull, 'rb', buffering=0))
File "/home/raul/Downloads/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/stubs.py", line 260, in __init__
raise IOError(errno.EACCES, 'file not accessible', filename)
IOError: [Errno 13] file not accessible: '/dev/null'
Any ideas what might be causing this and how to fix it?
The GAE Python sandbox is pretty restrictive in terms of what your app code is allowed to do. It looks like the dill package used by apache-beam needs to access special files (the /dev/null device file in this case) which is not allowed on the sandbox.
You either change your code to meet all sandbox requirements or try to use the flexible environment, which is a lot more tolerant (but it's a different beast overall). See Choosing an App Engine Environment and Migrating Services from the Standard Environment to the Flexible Environment.
Side note: the traceback indicates your app tried to execute apache-beam from the local system installation, which also won't work in the standard environment - it needs to be vendored into your application, see Installing a third-party library.
I have IIS setup with fastCGI, serving a flask app. So far so good. Next I whish to add some database connectivity, so I add the line import cx_Oracle to my app. Now this error is thrown:
Error occurred while reading WSGI handler:
Traceback (most recent call last):
File "D:\Anaconda2\lib\site-packages\wfastcgi.py", line 791, in main
env, handler = read_wsgi_handler(response.physical_path)
File "D:\Anaconda2\lib\site-packages\wfastcgi.py", line 633, in read_wsgi_handler
handler = get_wsgi_handler(os.getenv("WSGI_HANDLER"))
File "D:\Anaconda2\lib\site-packages\wfastcgi.py", line 616, in get_wsgi_handler
raise ValueError('"%s" could not be imported%s' % (handler_name, last_tb))
ValueError: "Bloomberg_server.app" could not be imported:
Traceback (most recent call last):
File "D:\Anaconda2\lib\site-packages\wfastcgi.py", line 600, in get_wsgi_handler
handler = __import__(module_name, fromlist=[name_list[0][0]])
File "D:\website\init__.py", line 6, in import cx_Oracle
ImportError: DLL load failed: The specified module could not be found. StdOut: StdErr:
As the title suggests I fail to reproduce the issue in a controlled environment. The very same import statement works fine in the conda environment and moreover, I can run the Flask debug server just fine with pages that rely on a database connection.
I am at loss. Who has a clue what's going on here? The path/oracle_home variables are pointing to the instant client and I have only one python environment installed.
I am too embarrased to admit how long this has taken me, but I've found the answer.
FastCGI's core business is keeping subprocesses alive so that subsequent calls to the server do not require booting a Python environment. In other words, after installing a python package it is advised to reboot. I solved my first question on SO by rebooting..
The answer to this question got me thinking in the right direction.
I am trying to use google endpoint v2
following this tutorial
I have done all steps up until the To generate the required configuration file: Step
But when i try the following command
python lib/endpoints/endpointscfg.py get_swagger_spec main.EchoApi --hostname echo-api.endpoints.xxxxxxx.appspot.com
I get the following warning and error
WARNING: Could not find the fix_sys_path() function in dev_appserver.
If you encounter errors, please make sure that your Google App Engine
SDK is up-to-date. Traceback (most recent call last):
File "lib/endpoints/endpointscfg.py", line 59, in
import _endpointscfg_setup # pylint: disable=unused-import
File "D:\Libraries\Documents\transporter\lib\endpoints_endpointscfg_setup.py",
line 107, in
`
_SetupPaths()
File "D:\Libraries\Documents\transporter\lib\endpoints_endpointscfg_setup.py",
line 103, in _SetupPaths
from google.appengine.ext import vendor ImportError: No module named google.appengine.ext
And no OpenAPI configuration file is generated
I have reinstalled everything,updated everything , checked system variables but still getting the error
p.s on windows 7
#HondaGuy's Comment was the answer I added app-engine to my python path,
my python environment variable now looks like this
C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk;C:\Program
Files (x86)\Google\Cloud
SDK\google-cloud-sdk\platform\bundledpython;C:\Program Files
(x86)\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine;
I want the line
import dropbox
to work. I downloaded the Python Core API from Dropbox, and copied the contents of the zip file into my (otherwise working) app's folder. When I run my app, it gives me the following error:
ERROR 2013-08-07 19:47:04,111 wsgi.py:219]
Traceback (most recent call last):
File "/home/myusername/Downloads/google_appengine/google/appengine/runtime/wsgi.py", line 196, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/home/myusername/Downloads/google_appengine/google/appengine/runtime/wsgi.py", line 255, in _LoadHandler
handler = __import__(path[0])
File "/home/myusername/Downloads/appname/appname.py", line 1, in <module>
import dropbox
File "/home/myusername/Downloads/appname/dropbox/__init__.py", line 3, in <module>
from . import client, rest, session
File "/home/myusername/Downloads/appname/dropbox/client.py", line 14, in <module>
from .rest import ErrorResponse, RESTClient
File "/home/myusername/Downloads/appname/dropbox/rest.py", line 7, in <module>
import pkg_resources
ImportError: No module named pkg_resources
How do I resolve this error?
As indicated by the link posted by #Tim Dierks, you can solve this issue by creating a pkg_resouces module within the dropbox folder with the contents
def resource_filename(*args):
cert_path = '/path/to/trusted-certs.crt'
return cert_path
As far as I can tell, pkg_resources only needs one method that returns the path to a certificate. trusted-certs.crt should be in your dropbox source folder.
You need to also package and distribute the pkg_resources module into your App Engine app. However, from what I've seen elsewhere, you'll run into some other challenges thereafter. It looks like the answers to Writing files to Dropbox account from GAE have gotten this working (for put, anyway).