Foreman start results in server error 500 - python

I am following Getting Started with Django on Heroku tutorial to deploy my app. First to test locally, I ran foreman start:
| => foreman start
00:47:08 web.1 | started with pid 4465
00:47:09 web.1 | 2013-11-21 00:47:09 [4465] [INFO] Starting gunicorn 18.0
00:47:09 web.1 | 2013-11-21 00:47:09 [4465] [INFO] Listening at: http://0.0.0.0:5000 (4465)
00:47:09 web.1 | 2013-11-21 00:47:09 [4465] [INFO] Using worker: sync
00:47:09 web.1 | 2013-11-21 00:47:09 [4468] [INFO] Booting worker with pid: 4468
Then in Chrome I went to http://0.0.0.0:5000/rides/ (also http://localhost:5000/rides/), it is returning Server Error 500.
My project urls.py:
url(r'^rides/', include('rides.urls')),
url(r'^admin/', include(admin.site.urls)),
Below is my Procfile:
web: gunicorn rides_project.wsgi
requirements.txt:
Django==1.6
South==0.8.3
dj-database-url==0.2.2
dj-static==0.0.5
django-localflavor==1.0
django-toolbelt==0.0.1
gunicorn==18.0
psycopg2==2.5.1
static==0.4
wsgiref==0.1.2
How can I troubleshoot this? Thank you for your help in advance.

Can you navigate to /admin successfully? If so, I would ensure that your DEBUG setting is set to True so that you can get a traceback through the browser to help determine the root cause of the 500 error.

Related

Python + FastAPI + OracleCloud: How to expose my python fastapi endpoint on Oracle Cloud to Internet

I have a Python + FastAPI restful API project running the free tier of Oracle Cloud VM instance.
I use Gunicorn to serve the api and also installed Nginx just in case it's needed.
I have tested my running project with
curl http://localhost:8000
and I can see my API response.
Now my question is : how can I expose this api endpoint outside on the Internet?
Update 1
I started my Python API project with this command:
gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app --timeout 1200 -b 0.0.0.0
I saw the messages below:
[2021-05-23 00:40:28 +0000] [3850] [INFO] Starting gunicorn 20.0.2
[2021-05-23 00:40:28 +0000] [3850] [INFO] Listening at: http://0.0.0.0:8000 (3850)
[2021-05-23 00:40:28 +0000] [3850] [INFO] Using worker: uvicorn.workers.UvicornWorker
[2021-05-23 00:40:28 +0000] [3853] [INFO] Booting worker with pid: 3853
[2021-05-23 00:40:28 +0000] [3854] [INFO] Booting worker with pid: 3854
[2021-05-23 00:40:28 +0000] [3857] [INFO] Booting worker with pid: 3857
[2021-05-23 00:40:28 +0000] [3858] [INFO] Booting worker with pid: 3858
[2021-05-23 00:42:04 +0000] [3853] [INFO] Started server process [3853]
[2021-05-23 00:42:04 +0000] [3857] [INFO] Started server process [3857]
[2021-05-23 00:42:04 +0000] [3857] [INFO] Waiting for application startup.
[2021-05-23 00:42:04 +0000] [3858] [INFO] Started server process [3858]
[2021-05-23 00:42:04 +0000] [3858] [INFO] Waiting for application startup.
[2021-05-23 00:42:04 +0000] [3858] [INFO] Application startup complete.
[2021-05-23 00:42:04 +0000] [3853] [INFO] Waiting for application startup.
[2021-05-23 00:42:04 +0000] [3853] [INFO] Application startup complete.
[2021-05-23 00:42:04 +0000] [3857] [INFO] Application startup complete.
[2021-05-23 00:42:04 +0000] [3854] [INFO] Started server process [3854]
[2021-05-23 00:42:04 +0000] [3854] [INFO] Waiting for application startup.
[2021-05-23 00:42:04 +0000] [3854] [INFO] Application startup complete.
Then I copied the IP address from the Compute >> Instances >> Instance Details panel and accessed it from my Chrome. Straightaway, it shows me
Unable to connect
Also read through several articles about using Nginx and tried without any luck.
Update 2
Using curl to access the website from my local machine
$ curl http://168.138.12.192:8000/
curl: (7) Failed to connect to 168.138.12.192 port 8000: No route to host
However, when access the IP directly using curl, I was able to get the default Nginx website.
$ curl http://168.138.12.192
Finally, I found out what I missed:
sudo iptables -I INPUT -p tcp -s 0.0.0.0/0 --dport 8000 -j ACCEPT
I have to run this command to open the port 8000(yes, my website is using port 8000).
I thought I have added Ingress Rule to accept tcp 8000, but it turns out that I still need to run the aforementioned command.
I do not quite understand why I need to do it, but it solves the problem.
Did you changed the default html page under /var/www/html directory? If not try customize the html page as per your requirement and see if it works for you or else it would just show the default nginx page when accessed from browser using public IP.
Adding to this, Also check if the port 8000 is allowed in the security list and OS firewall. The default port for http request is 80, you need to change the default port from 80 to 8000 in the config file to make this work. refer this page this might be useful How to Change Apache HTTP Port in Linux.

Google App Engine deployment issue- main app not found

I am trying to deploy my app using Google App Engine. I have edited app.yaml to reflect the flexible environment and also gave all the app information. Below is the app.yaml file.
runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app
runtime_config:
python_version: 3
Once the deployment is in progress, I am getting the following error
[2018-08-24 06:57:14 +0000] [1] [INFO] Starting gunicorn 19.7.1
[2018-08-24 06:57:14 +0000] [1] [INFO] Listening at: http://0.0.0.0:8080 (1)
[2018-08-24 06:57:14 +0000] [1] [INFO] Using worker: sync
[2018-08-24 06:57:14 +0000] [7] [INFO] Booting worker with pid: 7
App Deployed
Failed to find application: 'main'
[2018-08-24 06:57:14 +0000] [7] [INFO] Worker exiting (pid: 7)
[2018-08-24 06:57:14 +0000] [1] [INFO] Shutting down: Master
[2018-08-24 06:57:14 +0000] [1] [INFO] Reason: App failed to load.
Please note that App Deployed is the line in my print statement. It is getting executed. But the deployment is getting failed
Thank you in advance
In your app.yaml, you're starting gunicorn with gunicorn -b :$PORT main:app. This tells it to look for the object app in the file main.py
The error you're getting comes from gunicorn and occurs when you have a main.py file, but it does not have an app object in it.
You probably want to set up a Flask app as follows:
from flask import Flask
app = Flask(__name__)
See a full example app here: https://cloud.google.com/appengine/docs/flexible/python/quickstart#hello_world_code_review
I have had the same issue.
Failed to find application: 'main'
The reason in my case was that I had a directory called also main in the root project directory.
drwxr-xr-x 2 user staff 64 Nov 30 10:12 main
-rw-r--r-- 1 user staff 1178 Nov 29 20:58 main.py
I guess gunicorn got confused.
The solution (worked for me): to rename main directory.
P.S. Just don't rename it to code directory. It will cause another issue with debugging in PyCharm. :)
My folder structure is looks llike this the main.py is not in the root directory how I can specify this in app.yaml file.
/app
|__main.py
app.yaml

Running a Simple Falcon App

I've a simple falcon app straight from the getting started example
import falcon
import json
class QuoteResource:
def on_get(self, req, resp):
"""Handles GET requests"""
quote = {
'quote': 'I\'ve always been more interested in the future than in the past.',
'author': 'Grace Hopper'
}
resp.body = json.dumps(quote)
api = falcon.API()
api.add_route('/quote', QuoteResource())
The code is in a file called manage.py
When I try to run gunicorn manage:app
This is what I get
2017-06-04 20:47:18 -0700] [2370] [INFO] Starting gunicorn 19.7.1
[2017-06-04 20:47:18 -0700] [2370] [INFO] Listening at: http://127.0.0.1:8000 (2370)
[2017-06-04 20:47:18 -0700] [2370] [INFO] Using worker: sync
[2017-06-04 20:47:18 -0700] [2373] [INFO] Booting worker with pid: 2373
Failed to find application: 'manage'
[2017-06-04 20:47:18 -0700] [2373] [INFO] Worker exiting (pid: 2373)
[2017-06-04 20:47:18 -0700] [2370] [INFO] Shutting down: Master
[2017-06-04 20:47:18 -0700] [2370] [INFO] Reason: App failed to load.
What am I doing wrong here?
Not sure whether it is a typo or because of misunderstanding but you should start the application this way:
gunicorn manage:api
But not gunicorn manage:app
The manage:api option tells to invoke the api object defined in your manage.py module. Otherwise you need to rename api variable to app in your code.
Then you can check that application is running by accessing the following url:
http://localhost:8000/quote
By default the port should 8000 but you need to check it when gunicorn starts. It should be something like this:
[INFO] Listening at: http://127.0.0.1:8000

django app in heroku getting worker timeout error

I have deployed a django app and deployed to Heroku it takes facebook account id's as input through CSV file
and parses information. it works fine in the local server but I am getting the below mentioned error when I try to upload a larger CSV file.
14:12:16 web.1 | 2014-07-17 14:12:16 [30747] [INFO] Using worker: sync
14:12:16 web.1 | 2014-07-17 14:12:16 [30752] [INFO] Booting worker with pid: 30752
14:13:21 web.1 | 2014-07-17 14:13:21 [30747] [CRITICAL] WORKER TIMEOUT (pid:30752)
14:13:21 web.1 | 2014-07-17 03:43:21 [30752] [INFO] Worker exiting (pid: 30752)
14:13:21 web.1 | 2014-07-17 14:13:21 [30841] [INFO] Booting worker with pid: 30
Heroku requests are limited to 30 seconds, if the request take longer than this the router will terminate the request
You can increase the LOG LEVEL of gunicorn to see if there's some error in your process
Example of Procfile with timeout increased to 15 sec
web: gunicorn myproject.wsgi --timeout 15 --keep-alive 5 --log-level debug

Gunicorn doesn't work

I'm trying to deploy my django app on heroku. After following the steps instructed by the official document, the dyno I launched always crashes. Then I went through the whole process, and I think the problem might lie on the gunicorn part.
Following the instruction, I set the Procfile as 'web: unicorn hellodjango.wsgi', and when I $foreman start, it only shows "21:21:07 web.1 | started with pid 77969". It didn't say where the web is launched.
Then I tried to test whether gunicorn is working well. So I tried: "$gunicorn hellodjango.wsgi:application", it indeed doesn't work.
I think the path is correct because in current folder there's a hellodjango folder and inside there's the file wsgi.py.
What might be the problem?
One of the changes in later versions of gunicorn includes not logging to stdout/stderr. Add the argument --log-file=XXX, then examine that log file for what port it's running on.
Try setting your Procfile to:
web: gunicorn hellodjango.wsgi:application
write this in your Procfile:
web: gunicorn hellodjango.wsgi --log-file -
it will log everything to the screen like this:
(your_virtualenv)[~/Projects/myproj]$ foreman start
17:03:57 web.1 | started with pid 79137
17:03:58 web.1 | 2014-10-16 17:03:58 [79137] [INFO] Starting gunicorn 19.0.0
17:03:58 web.1 | 2014-10-16 17:03:58 [79137] [INFO] Listening at: http://0.0.0.0:5000 (79137)
17:03:58 web.1 | 2014-10-16 17:03:58 [79137] [INFO] Using worker: sync
17:03:58 web.1 | 2014-10-16 17:03:58 [79140] [INFO] Booting worker with pid: 79140

Categories

Resources