Reputation: 249
This is about Google Cloud, Google App Env standard, for python, version 3.X, mail bundled services.
According to this document from GCP, bundled mail is re-enabled in GAE for python3, which is very good news.
According to the doc, and the git samples it references, you are supposed to import mail from google.appengine.api, but on a local development machine that doesn't work: Importing google collides with the standard google library in the framework.
Here's what happens:
~: echo $PYTHONPATH
/Users/lehavi/google-cloud-sdk/platform/google_appengine
~: python
Python 3.10.10 (v3.10.10:aad5f6a891, Feb 7 2023, 08:47:40) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import google
>>> google.__path__
_NamespacePath(['/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/google'])
>>>
The google module is taken from a different place, not the appengine, even though I forced my PYTHONPATH to the latter (google.appengine.api.mail is located in that path.)
Any idea how to work around this and test my code locally before deploying to the cloud?
Thank you!
Upvotes: 0
Views: 131
Reputation: 6323
When using Python 3, you should create a virtual env
You also have to add appengine-python-standard>=1.0.0
to your requirements.txt
file and app_engine_apis: true
to your app.yaml
file
When you run your app with dev_appserver.py app.yaml
, it will install the bundled APIs in your virtual env and so all imports such as from google.appengine.api import mail
will come from the virtual env and not the standard google library in the framework or your google cloud sdk directory.
When you're on dev environment, you'll get the following message when you send a mail -
....You are not currently sending out real email. If you have sendmail installed you can use it by using the server with --enable_sendmail...
Upvotes: 2