I am deploying a django-nonrel app on Google App Engine. The app deploys alright but I can't login to the remote shell.
This is my app.yaml file:
application: masnun
version: 1
runtime: python
api_version: 1
builtins:
- remote_api: on
inbound_services:
- warmup
handlers:
- url: /_ah/queue/deferred
script: djangoappengine/deferred/handler.py
login: admin
- url: /media/admin
static_dir: django/contrib/admin/media
expiration: '0'
- url: /.*
script: djangoappengine/main/main.py
But I am getting an error:
urllib2.URLError: <urlopen error HTTP Error 500: Internal Server Error
Couldn't reach remote_api handler at https://masnun.appspot.com/_ah/remote_api(/.*)?.
Make sure you've deployed your project and installed a remote_api handler in app.yaml.>
Please help me out!
Update: When using Python2.5, getting this error:
DEBUG:google.appengine.tools.appengine_rpc:Got http error, this is try #3
DEBUG:google.appengine.tools.appengine_rpc:Sending HTTPS request:
GET /_ah/remote_api(/.*)? HTTPS/1.1
Host: masnun.appspot.com
X-appcfg-api-version: 1
Content-type: application/octet-stream
User-agent: Google-remote_api/1.0 Linux/2.6.35-25-generic Python/2.5.5.final.0
Add this on app.yaml section handlers, first item:
handlers:
- url: /remote_api
script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
login: admin
and deploy again.
The problem is with
GET /_ah/remote_api(/.*)? HTTPS/1.1
If you notice, the URL contains invalid characters "(/.*)?" towards the end.
Assuming you are using django-nonrel, it is an easy fix. Open the file
djangoappengine/db/base.py
and change the line
self.remote_api_path = handler.url
to
self.remote_api_path = handler.url.split('(')[0] # remove '(/.*)' introduced in newer GAE
and that should take care of ensuring the URL is correct.
You can connect to the remote shell using
python manage.py remote shell
and only if you created your App Engine app with Google Accounts Authentication. But remote_api requires a deployed app and since your
python manage.py deploy
fails, the above error is normal.
What error do you get when you try to deploy?
Related
I am trying to deploy my django site to gcloud, everything upload just fine but when I follow the link I get a 502 bad gateway error. I was following the gcloud tutorial for app engine with no luck.
This is my app.yaml
runtime: python 39
resources:
memory_gb: 4
handlers:
url: /static/
static_dir: /static/
url: /.*
script: auto
I'm new to django and gcloud so any help would be greatly appreciated.
There should be no space between python and 39:
runtime: python39
I try to run django and email handler app together in Google App Engine. I use code as google's doc and it must be run with python27. When I converted to code for python37 got script must be set to "auto" error. Can anyone help me? My code as below. Thanks in advance
app.yaml:
runtime: python37
entrypoint: gunicorn -b :$PORT myproject.wsgi
env_variables:
...
inbound_services:
- mail
- mail_bounce
handlers:
- url: /static
static_dir: static
- url: /_ah/mail/.+
script: handle_incoming_email.app
login: admin
handle_incoming_email.py:
import logging
from google.appengine.ext.webapp.mail_handlers import InboundMailHandler
class IncomingMailHandler(View, InboundMailHandler):
def receive(self, mail_message):
logging.info("Received a message from: " + mail_message.sender)
when I run this error raises from 'script: handle_incoming_email.app' script must be set 'auto'. How can I get handle_incoming_email.py to app.yaml if I set script: auto.
change '.+' as '.*' have tried.
In App Engine Standard, when using the Python3.7 runtime, the script tag under the handlers must be set to auto. You can check the documentation on this here on how the app.yaml must be configured, note that it's different than in the Python2.7 runtime, where you had to specify the script to run.
You can solve this by modifying your app.yaml file, like so:
runtime: python37
entrypoint: gunicorn -b :$PORT handle_incoming_email.app
env_variables:
...
inbound_services:
- mail
- mail_bounce
handlers:
- url: /static
static_dir: static
- url: /_ah/mail/
script: auto
login: admin
Notice how the required change was to set the script under /_ah/mail/ to auto, instead of specifying the path to the script to run. The handler then should automatically find the script to execute, from the files you deployed in App Engine.
Next, in your handle_incoming_email.py file you are not defining any entrypoint to handle your url /_ah/mail, you can solve this by adding the following, for example:
import webapp2
app = webapp2.WSGIApplication([
('/_ah/mail/', IncomingMailHandler),
], debug=True)
Notice now, how I changed the entrypoint in your app.yaml file to match the newly created WSGI entrypoint in your handle_incoming_email.py file.
Also I'm not sure about the '/.+' regex for the handler, you should leave it at '/.*'.
The handler parameter is used to route requests to static files, then the remaining routes are all routed to your main app (the auto value is the only option for the script element, as mentioned in the doc) at your entrypoint. That app must handle requests routing. You can't define another app in the same service.
I'd suggest to deploy your email app as a separate service in your App Engine app. This will allow you to specify specific resources or scaling for each one. This will follow the micro-services architecture principles enforced in App Engine.
I have Google App Engine and Python running on http://localhost, which is fine working. But for making it reliably working i need to add https, Google App Engine do not have it.
So i have been trying stunnel and apache to make https working. I tried following but its still not working.
NameVirtualHost example.stackoverflow.com:443
<VirtualHost example.stackoverflow.com:443>
SSLEngine on
SSLProxyEngine On
ProxyPreserveHost On
#ProxyRequests Off
SSLProtocol all -SSLv2
SSLCipherSuite ALL:!ADH:!EXPORT:!SSLv2:RC4+RSA:+HIGH:+MEDIUM:+LOW
SSLCertificateFile /etc/stunnel/a.crt
SSLCertificateKeyFile /etc/stunnel/a.key
SSLCertificateChainFile /etc/stunnel/b.ca
ServerName localhost
ProxyPass / http://localhost
ProxyPassReverse / http://localhost
#ProxyPassReverseCookiePath /MYSITE/ /
CacheDisable *
</VirtualHost>
when a user visit: https://example.stackoverflow.com, basically his browser address get changed from https:// to http://example.stackoverflow.com and he is able to use the Google App Engine and Python instances.
But i need to have https for Google App Engine with my python. How can i resolve it please?
EDIT: secure is used but still not working
application: rtc
version: 6
runtime: python27
threadsafe: true
api_version: 1
handlers:
- url: /html
static_dir: html
- url: /images
static_dir: images
- url: /js
static_dir: js
- url: /css
static_dir: css
- url: /.*
script: rtc.app
secure: always
inbound_services:
- channel_presence
libraries:
- name: jinja2
version: latest
Google App Engine does support HTTPS, you just need to sign up for it. It is not free, but it isn't too expensive either.
More information on the types of SSL provided is available at: SSL for a Custom Domain.
Also, if you want to automatically redirect users to the secure site, you can use the secure keyword in Google App Engine's app.yaml configuration file. See Secure URLs.
I'm working on my first GAE project and I'm having some trouble getting custom pages to show up in the Admin Console. I'm following the Google Docs on it, but it doesn't seem to be working for me. I have a feeling it could have something to do with this note:
Note: Only custom pages defined by the default version will be shown
in the Admin Console.
but I'm not entirely sure what they mean (the default version of the app?).
The page URLs work fine if I visit them directly, but the links will not show in the Admin Console sidebar.
YAML:
application: namegenerator
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /css
static_dir: css
- url: /admin/.*
script: main.app
login: admin
- url: /.*
script: main.app
libraries:
- name: jinja2
version: latest
builtins:
- remote_api: on
admin_console:
pages:
- name: Manual DB Entry
url: /admin/db/add
- name: Clear DB
url: /admin/db/clear
Python routing:
app = webapp2.WSGIApplication([('/', MainHandler),
('/vote', SubmitVote),
('/clear_session', ClearUserSession),
('/admin/db/clear', ClearDatabase),
('/admin/db/add', ManualAddToDatabase)],
debug=True)
This is all being tested and run on my local machine, by the way. Thanks for any help.
Your code looks fine to me. Did you deploy your application? I think the admin pages will not be shown in your SDK.
By the way: An administrator can change which major deployed version of the application is default using Administration Console: https://appengine.google.com/
I'm using the latest version of Google App Engine, Python 2.7 and webapp2, but enabling debug mode just gives me a blank HTML page on error rather than displaying the error and stack trace. This does not seem like the expected behavior:
"When in debug mode, any exception that is now caught is raised and the stack trace is displayed to the client"
http://webapp-improved.appspot.com/guide/app.html
Am I doing something wrong? If not, how can I print the stack trace using a custom error handler in webapp2?
Thanks.
EDIT: Here's an example app that reproduces the error:
app.yaml
application: testapp
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: main.app
libraries:
- name: jinja2
version: "2.6"
main.py
import webapp2
# Run application
app = webapp2.WSGIApplication([webapp2.Route('/', handler='handlers.IndexHandler')], debug=True)
Because there is no file called "handlers.py" containing IndexHandler, this app throws a 500 server error. But even though debug = True, the app just shows an empty page, and does not output the error and stack trace, except in the App Engine log.
I have not tried this on the production server.
Seems like this bug was fixed in the latest version of webapp2:
http://code.google.com/p/webapp-improved/source/detail?r=da20281cbba3f593ca49667752c0a2395ea483c5
I guess the fix will be included in the App Engine SDK eventually.