Internal Server Error on Django Deploy - python

Im getting 500 internal server error everytime I try access my admin or login page. There's nothing in my error.log
Any ideas ?

Set DEBUG = True so that you can see the Django traceback

My DEBUG was set True. I found the error on my apache_log. The problem was that my sqlite3 database was a read only file.

Related

Python Flask doesn't serve custom 500 template/return on IIS

I am using Flask and blueprints on IIS. My issue is that when the 500 error is triggered it loads the default IIS 500 template and not what I want.
I've tried several things and this is where I am. I have the following code
from flask import render_template,Blueprint
errorbp = Blueprint("errorbp",__name__)
#errorbp.app_errorhandler(404)
def page_not_found(e):
return "404", 404
#errorbp.app_errorhandler(500)
def internal_server_error(e):
return "500", 500
If I visit a page that does not exist, I get "404" back as intended. If I create an error on purpose, I get the following
Any suggestions as to what to do? I presume I may need to do something with IIS at this point but what? I've edited/remove the 5xx status codes/page and still nothing
What you need to do is, open the error pages module, double-click the 500 status code, set the path of your template in the file path, and IIS will send the content of the file as a custom error response.
In addition, IIS has two other ways to respond to an error: by executing an URL or by redirecting the request.

KeyCloak Admin Functionality in Python

Am trying to access Keycloak Admin for getting the user information with following code. Am getting 403 error while executing any GET commands.Can anyone help or have seen this in error. Am getting 'None' when am priniting, print(keycloak_admin1.get_token()).
from keycloak import keycloak_admin
keycloak_admin1 = keycloak_admin.KeycloakAdmin(server_url=endpoint,username=username, password=password,realm_name=realmname,client_id= clientid,client_secret_key=clientsecret,verify= True)
print(keycloak_admin1.realm_name)
print(keycloak_admin1.token)
# User counter
count_users = keycloak_admin1.users_count()
getusers = keycloak_admin1.get_user()
print(count_users)
I ended up using Keycloak API's and it resolved my issue. Still not sure why python.keycloak package not working. So marking this issue done.

Django 400 Bad request after pulling update from Github

I had a working page running Django with channels via Nginx, Daphne, Redis, and Gunicorn. After pulling an update from Github my index page now shows "Bad Request (400)" with nothing helpful in the console except for missing favicon. My settings.py has DEBUG = False and ALLOWED_HOSTS = ['AWS_IP']. Can anyone help me figure out what might be causing this?

django's ALLOWED_HOSTS throws error 500?

In my Django project's settings.py for deployment i want mywebsite.com to be the allowed hosts but putting it so throws the 500 error.
For production server when i use:
ALLOWED_HOSTS = ['localhost', 'mywebsite.com']
It throws error 500 on every page.
But if i change it to
ALLOWED_HOSTS = ['*']
It works fine.
I checked error.log of nginx but there is not error logged.
But i guess its not safe to keep * and i just want to keep mywebsite.com or www.mywebsite.com
Please suggest why its throwing 500 error.
Thanks
Probably a duplicate of Allowed Host Setting for Django on EC2 where I can find the answer working fine (as they have accepted it). Please try it like and check if this works.
ALLOWED_HOSTS = ['.mywebsite.com']

Getting 'No handlers could be found for logger "foursquare"' error using Flask on Heroku. Error doesn't occur when using localhost

I've got a website that uses the Foursquare python API and the Flask framework.
Everything has been working great, but when I pushed my code to my heroku server, I started getting this error: FoursquareException: Error connecting with foursquare API.
This is the code that is being run (the variables all point to the valid information):
fsq_client = Foursquare(client_id=fsq_client_id, client_secret=fsq_client_secret, redirect_uri=redirect_uri)
#app.route('/fsq/explore')
def fsq_explore():
lat = request.args.get('lat', '')
lng = request.args.get('lng', '')
params = {}
params['ll'] = str(lat) + ',' + str(lng)
data = fsq_client.venues.explore(params)
return json.dumps(data)
I'm also seeing an error in my Heroku logs that says that No handlers could be found for logger "foursquare".
I've never seen that error before.
I've tried running the code on my localhost, and everything is totally fine. I even input each line of code into python in terminal and it all returned correctly. It seems to be a problem specific to the Heroku server.
Is there anything that I should lookout for? Any setting I should play with or requirement I should make sure I have?
I was experiencing the same problem on heroku. The error about the logger can be solved by putting this in your app.py (or wherever your Flask app is located):
import foursquare
import sys
import logging
loghandler = logging.StreamHandler(stream=sys.stdout)
foursquare.log.addHandler(loghandler)
foursquare.log.setLevel(logging.DEBUG)
In Heroku everything that is writting through sys.stdout is saved in "heroku logs", so you will see the message that was written to the log there.
Then you can see what problem the foursquare library was raising, in my case it seems to be something with the SSL-certificates. I'm still working on that problem.

Categories

Resources