Why Flask session is not working in heroku? - python

I just created one web app with the help of Flask and Heroku but when I started using session for log in stuff then in local (in my computer) its working fine but when I deployed it on heroku then its showing error: Internal Server Error
Can anyone help me with this ?
#app.route('/')
def home():
''' Home page'''
if 'username' in session:
session['logged_in'] = True
else:
session['logged_in'] = False
return render_template('home.html')
As soon as it come to 'if' line then server stops and shows error but if i run this locally then it works fine. I just pasted the small part of my code showing where it shows error.
Is it possible that for heroku we need to implement it differently or heroku doesn't support session.

Check if you have set app.config['SECRET_KEY']. If not, flask will report an error.

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/

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

Recently used an old script using Ngrok but now it doesnt work

Basically I just booted up an older script that I made 1-2 months ago and which worked perfectly at the time, but now when I try to connect to the ngrok tunnel i get a 404 and a "Tunnel xxxx not found"
I have a non-paying user, which didn't use to be a problem and I cant see anywhere that they changed their terms of service and I can find the tunnel on the dashboard but not connect, any idea what is wrong and if they changed something?
I just booted an old super simple test script which also doesn't work, I can see the tunnel but it returns "Funnel xxxx not found" and server 404:
from flask import Flask
from flask_ngrok import run_with_ngrok
app = Flask(__name__)
run_with_ngrok(app) #starts ngrok when the app is run
#app.route("/")
def home():
return "<h1>Running Flask on Google Colab!</h1>"
app.run()

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