Flask

Flask on nginx + uWSGI returns a 404 error unless the linux directory exists

主宰稳场 提交于 2021-02-10 06:34:26
问题 This might be kind of a strange problem, but I'm not too experienced with these things and I don't know how to search for this kind of error. I have a server configured with nginx and uWSGI. Everything runs fine, no errors in the logs that I can see. However, when I'm executing the below code: from flask import Flask app = Flask(__name__) @app.route('/test/') def page1(): return 'Hello World' @app.route('/') def index(): return 'Index Page' I can not view http://ezte.ch/test/ UNLESS the /test

Unable to connect to CloudSQL from Kubernetes Engine (Can't connect to MySQL server on 'localhost')

南笙酒味 提交于 2021-02-10 06:30:52
问题 I tried to follow the steps in: https://cloud.google.com/sql/docs/mysql/connect-kubernetes-engine. I have the application container and the cloudsql proxy container running in the same pod. After creating the cluster, logs for the proxy container seems correct: $kubectl logs users-app-HASH1-HASH2 cloudsql-proxy 2018/08/03 18:58:45 using credential file for authentication; email=it-test@tutorial-bookshelf-xxxxxx.iam.gserviceaccount.com 2018/08/03 18:58:45 Listening on 127.0.0.1:3306 for

UnicodeDecodeError while starting the app under Windows with Pycharm

我与影子孤独终老i 提交于 2021-02-10 06:14:35
问题 The problem is that when i try to start the application (app.py) i get the following error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb3 in position 5: invalid start byte The whole file app.py: # -*- coding: utf-8 -*- from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return 'Hello World' if __name__ == "__main__": app.run(host='127.0.0.1') I read somewhere here on stackoverflow that this can help: # -*- coding: utf-8 -*- but it doesn't change anything.

UnicodeDecodeError while starting the app under Windows with Pycharm

眉间皱痕 提交于 2021-02-10 06:14:00
问题 The problem is that when i try to start the application (app.py) i get the following error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb3 in position 5: invalid start byte The whole file app.py: # -*- coding: utf-8 -*- from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return 'Hello World' if __name__ == "__main__": app.run(host='127.0.0.1') I read somewhere here on stackoverflow that this can help: # -*- coding: utf-8 -*- but it doesn't change anything.

Flask jsonify print results on new lines

丶灬走出姿态 提交于 2021-02-10 06:10:34
问题 First time using Flask, I have created a very basic app and I am trying to print the results of a recommender system. The first set of code is from my python function (print_most_similar) and is creating a formatted string in hopes to print every REC on a new line. The second section of code is obviously my flask routing. You can see that the flask part calls the function, so it is returned 'y'. I believe the jsonify will not take the \n characters. I have tried using just '\n' in the string

Python / Flask — server is receiving POST requests as GET requests

点点圈 提交于 2021-02-10 05:00:56
问题 I created an endpoint in the flask file that looks like this @app.route("/update", methods=['POST', 'GET']) def update_func(): results = { "method": request.method } return json.dumps(results) I tried calling this function using both Postman and python, both are saying Flask is processing it as a get request. import requests r = requests.post("http://site.fakeurl.org/update", json={}) print r.json() Is there a config file I need to change for this process as a POST request? Is this happening

Python / Flask — server is receiving POST requests as GET requests

六眼飞鱼酱① 提交于 2021-02-10 05:00:51
问题 I created an endpoint in the flask file that looks like this @app.route("/update", methods=['POST', 'GET']) def update_func(): results = { "method": request.method } return json.dumps(results) I tried calling this function using both Postman and python, both are saying Flask is processing it as a get request. import requests r = requests.post("http://site.fakeurl.org/update", json={}) print r.json() Is there a config file I need to change for this process as a POST request? Is this happening

Expire session in flask in ajax context

久未见 提交于 2021-02-10 03:27:43
问题 I am using permanent_session_lifetime to expire the session of the user after some period of inactivity. The problem is that, this request is made through ajax, so i can't redirect in ajax context with the normal behavior of the flask. http://xxxx/login?next=%2Fusers%2Fajax_step1 Instead of this, I want to redirect to my logout route in the before_request , if the flask session expire. How can i do that? @mod.before_request def make_session_permanent(): session.modified = True session

No module named 'application' Error while deploying simple web app to Elastic Beanstalk

放肆的年华 提交于 2021-02-10 03:27:42
问题 I am deploying a web app to elastic beanstalk using this tutorial and the same 'application.py' file they have: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-flask.html#python-flask-setup-venv I get a 502 error when going to the site, and degraded/severe health on the environment. When I check the logs, I see this (which I assume is the root of the problem): Jun 19 22:05:18 ip-172-31-15-237 web: File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in

No module named 'application' Error while deploying simple web app to Elastic Beanstalk

喜夏-厌秋 提交于 2021-02-10 03:27:41
问题 I am deploying a web app to elastic beanstalk using this tutorial and the same 'application.py' file they have: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create-deploy-python-flask.html#python-flask-setup-venv I get a 502 error when going to the site, and degraded/severe health on the environment. When I check the logs, I see this (which I assume is the root of the problem): Jun 19 22:05:18 ip-172-31-15-237 web: File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in