Internal Server Error when deploying Chalice (AWS) - python

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

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.

How can I solve "Method not Allowed" in Heroku deploy

I recently tried to deploy my telegram bot on Heroku and I use Flask framework for write webhook code. With using "git push heroku master" deploying my codes began with any problems, But at the end I encountered this problem that the link "https://git.heroku.com/serene-crag-92322.git" I get "Method Not Allowed" message. Please help me to solve this problem and thank you in advance.
My Flask code:
#app.route('/' + TOKEN, methods=['POST'])
def getMessage():
json_string = request.get_data().decode('utf-8')
update = telebot.types.Update.de_json(json_string)
bot.process_new_updates([update])
return "!", 200
#app.route("/")
def webhook():
bot.remove_webhook()
bot.set_webhook(
url='https://gentle-temple-77151.herokuapp.com/' + TOKEN)
return "!", 200
if __name__ == "__main__":
app.run()
The message from Heroku:
Heroku creates a git repository with your source code before building and deploying your code. You had tried to access that private Git repository, which is not accessible to the outside world (therefore, the Method Not Allowed error message appeared). But the actual website where your web app is deployed is different. That web app includes your app name, if you had given one during Heroku app creation, else a random name is given to your web app.
Heroku Git Repository Link: https://git.heroku.com/serene-crag-92322.git
Deployed Heroku App Link: http://serene-crag-92322.herokuapp.com/

How to migrate Twilio Python Script to AWS EC2 using Flask

I have built a SMS service (using Twilio) that the user texts to get realtime bus information. At the moment i have been hosting this on my personal computer using ngrok. Now i want to use AWS to host this service, but I am not sure as to how i should go about it. I have tried running a flask webserver and trying to get ngrok to run on AWS, but no luck.
Here is my code concerning Flask and Twilio's REST Api:
app = Flask(__name__)
#app.route("/sms", methods=['GET', 'POST'])
def hello_monkey():
resp = MessagingResponse()
response = request.form['Body']
if (" " in response):
response = response.split(" ")
result = look_up(response[0], response[1])
else:
result = look_up(response, False)
resp.message(result)
return str(resp)
if __name__ == "__main__":
app.run(debug=True)
There is a blog post on the Twilio blog on How to Send SMS Text Messages with AWS Lambda and Python 3.6. It does not use Flask, but it can definitely be modified to achieve your goal. Alternatively, you could read about using Flask with AWS Elastic Beanstalk here.
Running ngrok on AWS is not the correct approach to this. If you wanted to host your own Flask server, you could use something like Lightsail, but that's overkill for this usage.

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')

Flask app on pythonanywhere, python JSON decode error

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.

Categories