I am trying to deploy completed web-app (runs locally) on the app engine. The app has no databases and the web page is static. My primary problem is that I try to deploy the app and I get a server error. I suspect that the issue lies with my app.yaml file but I cannot seem to fix it. Here is my yml file:
runtime: python27
api_version: 1
threadsafe: yes
handlers:
- url: /static
static_dir: personal/static/
- url: /.*
script: mysite.wsgi.application
The directory is organized so that the 'personal' is an installed app and static, templates etc. are inside the personal folder.
In settings file, make DEBUG=False for short time to just check what is error, then return it back to True
Related
Ive been trying to my django website but I've been having the same 502 BAD CONNECTION nginx error every time and I'm not sure how to troubleshoot it.
When I run the program using py.manager runserver, it works perfectly fine, but but I only receive an error once I run gcloud app deploy, looking at the logs I haven't received any errors, just one warning stating that Container called exit(1).
I've tried one solution from the Google's website: https://cloud.google.com/endpoints/docs/openapi/troubleshoot-response-errors and I added resources: memory_gb: 4 to my app.yaml file and I still end up with an error.
I am not sure this is of much help my app.yaml currently looks like this:
runtime: python39
handlers:
# This configures Google App Engine to serve the files in the app's static
# directory.
- url: /static
static_dir: static/
# This handler routes all requests not caught above to your main app. It is
# required when static routes are defined, but can be omitted (along with
# the entire handlers section) when there are no static files defined.
- url: /.*
script: auto
resources:
memory_gb: 4
And my gcloudignore looks like this:
# This file specifies files that are *not* uploaded to Google Cloud Platform
# using gcloud. It follows the same syntax as .gitignore, with the addition of
# "#!include" directives (which insert the entries of the given .gitignore-style
# file at that point).
#
# For more information, run:
# $ gcloud topic gcloudignore
#
.gcloudignore
# If you would like to upload your .git directory, .gitignore file or files
# from your .gitignore file, remove the corresponding line
# below:
.git
.gitignore
secret_variables.py
.venv
Pipfile
Pipfile.lock
# Python pycache:
__pycache__/
# Ignored by the build system
/setup.cfg
Thank you in advance for the help
Cloned and tried running the code locally after running pip install -r requirements.txt. This is the error I got:
ModuleNotFoundError: No module named 'django_filters'
This means that this requirement needs to be added before the code is deployed to the GAE.
add django-filter to the requirements.txt file to fix it.
On GCP dashboard I get this error but on my machine all works fine:
ImportError: Could not import settings 'site.settings' (Is it on sys.path?): No module named settings
at __init__ (/base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/third_party/django-1.4/django/conf/__init__.py:95)
at _setup (/base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/third_party/django-1.4/django/conf/__init__.py:42)
at __setattr__ (/base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/third_party/django-1.4/django/utils/functional.py:207)
at <module> (/base/data/home/apps/g~unitutor-221411/1.413727868439486493/main.py:9)
at LoadObject (/base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py:85)
at _LoadHandler (/base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py:299)
at Handle (/base/alloc/tmpfs/dynamic_runtimes/python27g/3b44e98ed7fbb86b/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py:240)
This is my app.yaml:
application: *********
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /static
static_dir: static
- url: /.*
script: main.app
libraries:
- name: django
version: "1.4"
- name: jinja2
version: "latest"
Obviously I have, locally and on GCP, a directory "site" containing "settings.py". On my machine the app works well. I tried in many ways and I read many posts but I can't find a solution to solve the "500 Server Error" on GCP.
Local and production are two different things. You are getting this error because your paths are incorrectly handled in GCP. Try to check where it is looking for settings.py file and then reconfigure it.
I have the following files structure:
And shown below, is the part of the code of my app.yaml that's pointing to the wsgi of my project:
handlers:
- url: /static
static_dir: static/
- url: .*
script: testproject.wsgi.application
Of course there are other files which I think is not necessary to be shown, such as the other apps. When I ran it in local, everything is working fine. But when I upload it to the cloud, it's not working and is showing a server error. In the error log, it says, "Import Error: No module named testproject"
I have been researching a lot but still no luck. Please help me. Thanks!
You forgot src/:
Change the path to the file:
handlers:
- url: /static
static_dir: static/
- url: .*
script: src.testproject.wsgi.application
App Instances:
App Versions:
app.yaml:
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /my_uri
script: path.to.my.script.script.app
I created a Python Flask app with Google App Engine. I initially ran into some issues, so I re-deployed the app. This created a new version. After doing so, I deleted the previously existing version which had one instance deployed. The currently deployed version has no instances deployed, as you can see in the image at the link above.
When I submit a request to my-app-ID.appspot.com/my_uri, I get a 404 error:
Error: Not Found
The requested URL /my_uri was not found on this server.
I believe this is related to my app not having an instance deployed. Is that correct? If so, how would I remedy this?
If not, what could be causing the 404 issue?
Thanks everyone!
As your error message indicates gcloud app browse makes a request for the / url to your app.
From Request handlers:
When App Engine receives a web request for your application, it calls
the handler script that corresponds to the URL, as described in the
application's [app.yaml][2] configuration file . The Python 2.7
runtime supports the WSGI standard and the CGI standard for
backwards compatibility. WSGI is preferred, and some features of
Python 2.7 do not work without it. The configuration of your
application's script handlers determines whether a request is
handled using WSGI or CGI.
But your app.yaml file does not contain a handler with a matching url pattern (as / doesn't match /my_uri), so GAE doesn't know which app script to launch for that request, so it'll return 404.
So the first thing you have to do is to add in app.yaml a handler with a url pattern that matches a / request.
You may want to go through the Getting Started with Flask on App Engine Standard Environment guide. In there the recommended handler would be:
handlers:
- url: /.*
script: main.app
The above alone won't necessarily make your app work, there's plenty of other things that can go wrong. You should get familiar with the app's log viewer as that's essential for debugging your app. See Understanding request log fields
But before you even go to deployment on GAE, learn how to run and test your app locally. See Using the Local Development Server
My static files are not being served. What I have verified:
settings.STATIC_ROOT is properly defined: STATIC_ROOT = os.path.join(BASE_DIR, '..', 'collectstatic/')
settings.STATIC_URL is properly defined: STATIC_URL = '/static/'
I have done python manage.py collectstatic
The static files are indeed collected: my collectstatic/ directory has the right assets
The collectstatic/ directory is tracked in my git repo
I have pushed to the gae repo: git push google (I am not sure if gae is using the gae repo copy for staging, or my local repo)
When pushing to the gae repo, the assets are indeed present
I have redeployed the app: gcloud preview app deploy app.yaml --promote -q
My app.yaml is properly configured, as explained here
Specifically:
handlers:
- url: /static
static_dir: collecstatic
- url: .*
script: myproj.wsgi.application
Still I get 404 for:
https://my-site.appspot.com/static/admin/css/base.css
Why could this be? What else can I verify?
EDIT
On The logging tab of the Google Cloud Platform I see warning messages:
Static file referenced by handler not found:
collecstatic/admin/css/base.css
I would say all my settings are correct though.
How can I verify if my app instance has the right assets in the right places? Is there a way of checking the filesystem structure of a running instance?
Embarassing, but the problem was a spelling error. I had:
handlers:
- url: /static
static_dir: collecstatic
And should be:
handlers:
- url: /static
static_dir: collectstatic
I'll keep this. Maybe helps somebody else.