Flask app on pythonanywhere, python JSON decode error - python

I'm trying to replicate my app the runs on localhost, but on pythonanywhere.
I have a very basic API that provides a JSON response and it all works as expected on localhost:5000.
Moving the code to pythonanywhere, i get a 500 Internal Server Error
The route is:
#app.route('/api/get_authors', methods = ['GET'])
def get_authors():
authors = get_poi_authors()
return jsonify(authors)
And the problem seems to come from a line in my getPoiAuthors code:
poiData = json.loads(getResult)['pois']
This works as expected on my machine, but not on pythonanywhere. I get a 'No JSON object could be decoded' Error. Could it problems with python versions? I run 2.7.6.

Related

How do I access csgo server logs?

NOT : I only have rcon password
I want to retrieve the logs on the csgo server, but I couldn't do it.
I can use c# nodejs and python
I created a project in replit using python and flask and with logaddress_add_http.I added the link of this project to the csgo server and it worked, but I could not figure out how to get the logs by adding the ip of my own computer with the logaddress_add to the csgo server.
Please help me, I couldn't find any sources about this
log on
logaddress_add_http "https://CSGO.synx12.repl.co"
My Code:
from flask import Flask,request
app=Flask(__name__)
#app.route("/",methods=["GET","POST"])
def index():
if(request.method=="GET"):
return "GET"
elif(request.method=="POST"):
data=request.get_data()
print(data)
return f"Data : {data}"
if(__name__=="__main__"):
app.run(host="0.0.0.0",port=8080)
I'm sending a message to the server with rcon
And Result
here logaddress_add_http works fine but I couldn't get logaddress_add to work at all
I want your help for this.

Flask App deployed on Heroku returns error on post requests

I deployed my Flask App on Heroku, I noticed that once deployed post request in the API don't work anymore and the app just responds with status code 400 and "message": "The browser (or proxy) sent a request that this server could not understand.". Get requests work normally but post don't. Also I am quite confused because if I run the app on localhost everything works as expected but not once deployed. Anyone knows how to solve?
To parse request argument I use args = ParseArgs.parse_args() from flask_restful and I retrive the value with:
args = ParseArgs.parse_args()
mode = args['Mode']
value = args['Value']
I tried to look up on google and I saw that it might be the Content-Type header with value application/json, I removed it but the problem still persists.

Internal Server Error when deploying Chalice (AWS)

I am trying to deploy a simple REST API using Chalice. My basic boilerplate is
from chalice import Chalice
app = Chalice(app_name='helloworld')
#app.route('/')
def index():
return {'hello': 'world'}
When I call chalice local and run it on localhost 8000, there is no issue and I am able to get back the returns. However, after I deployed it and used the REST API URL that was returned, it didn't work anymore. I keep getting the
{"message": "Internal server error"}
I would appreciate any help!
Thanks!
Good news, it looks like you are reaching your lambda.
Check aws cloudwatch logs: /aws/lambda/helloworld-{dev|prod}
If can't solve it, upload .chalice/config.json and the error of the logs in clouwatch

500 Internal Server Error when trying to connect through Postman Using PyCharm

Hi I am trying to test my connection to my database on my local drive for a personal project I am working on. I am trying to get better with python and MongoDB. Every time I try to test my connection using postman I am getting a 500 internal error. I double checked my URI = mongodb://127.0.0.1:27017 like majority local. I even uninstalled and reinstalled mongoDB. Any advice or solutions would be highly helpful. In my PyCharm IDE I have my database file
import pymongo
__author__ = 'jslvtr'
class Database(object):
URI = "mongodb://127.0.0.1:27017"
DATABASE = None
#staticmethod
def initialize():
client = pymongo.MongoClient(Database.URI)
Database.DATABASE = client['fullstack']
#staticmethod
def insert(collection, data):
Database.DATABASE[collection].insert(data)
#staticmethod
def find(collection, query):
return Database.DATABASE[collection].find(query)
#staticmethod
def find_one(collection, query):
return Database.DATABASE[collection].find_one(query)
Here is my app file:
from flask import Flask
from src.common.database import Database
__author__ = 'jslvtr'
app = Flask(__name__)
app.config.from_object('config')
app.secret_key ='123'
#app.before_first_request
def init_db():
Database.initialize()
from src.models.users.views import user_blueprint
app.register_blueprint(user_blueprint, url_prefix="/users")
Here is my config file:
__author__ = 'jslvtr'
DEBUG = True
ADMINS = frozenset([
"christopher.jxxxx#gmail.com"
])
This is the error I keep receiving:
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"
500 Internal Server Error
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
You must check mongodb from command line first like below
C:\Program Files\MongoDB\Server\3.6\bin>mongo localhost:27017 ;
if it works then you can jump into the code;
the issue you are getting error 500 is reserved for server only, meaning it doesn't link to your database connectivity at all. The request you are sending is wrong as per the REST endpoint you defined. Please verify the request with your code. If the request matches with your code you will get connection timeout error from MongoDB if you cannot connect to mongodb from localhost.
I think once you are okay with request you will be able to get a success.
You can paste the request JSON for more help.

Accessing a config variable on heroku returns a 500 error

I have tested and set a config variable to heroku for my flask app using the following code:
api = os.environ.get['API_KEY']
Testing it on foreman seems to work, but returns a 500 internal server error when deployed on heroku. Would the error be caused by the code above?
The syntax is off. os.environ is a dictionary. So,
api = os.environ.get['API_KEY']
should either be
api = os.environ['API_KEY'] #Would raise exception if key is not found
or
api = os.environ.get('API_KEY')

Categories