Flask

HTML range slider to Flask with AJAX call

送分小仙女□ 提交于 2020-07-07 12:40:32
问题 I have a HTML control panel with various buttons and sliders. All of the buttons are operational and when clicked send a post request which my Python app receives and then executes functions. I cannot seem to get the slider controls to work, When I adjust the slider I get the following error: werkzeug.exceptions.BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand. KeyError: 'button' This is promising as at least I can see it trying

sqlite3.DatabaseError: file is not a database

℡╲_俬逩灬. 提交于 2020-07-07 11:33:26
问题 I get the above error for executing the below INSERT-statement. The database file ce.db is in the same directory as my code and I have successfully created the tables therein. My sqlite version is 2.8.17 and I am confident that my db file exists as I can see it in my directory and have succeeded in creating tables therein. import sqlite3 @app.route("/sign_up", methods=["GET", "POST"]) def sign_up(): # [..other code..] conn = sqlite3.connect("ce.db") c = conn.cursor() result = c.execute(

how can a bokeh server access arguments from server_document()

不想你离开。 提交于 2020-07-07 09:09:59
问题 I have a flask app which talks to a bokeh server. I want to pass arguments to the bokeh server so that the bokeh server can use that information to display things differently. Here's my flask route, complete with how I'm attempting to pass arguments to bokeh: @app.route('/test') def test(): return render_template( 'bokeh.html', template='Flask', script=server_document( url='http://localhost:6001/test', arguments={'foo': 'bar'} )) I think I'm passing the arguments correctly but I don't know

how can a bokeh server access arguments from server_document()

跟風遠走 提交于 2020-07-07 09:06:05
问题 I have a flask app which talks to a bokeh server. I want to pass arguments to the bokeh server so that the bokeh server can use that information to display things differently. Here's my flask route, complete with how I'm attempting to pass arguments to bokeh: @app.route('/test') def test(): return render_template( 'bokeh.html', template='Flask', script=server_document( url='http://localhost:6001/test', arguments={'foo': 'bar'} )) I think I'm passing the arguments correctly but I don't know

Why cannot I receive any POST request on my Telegram bot written with Flask (Python)?

北慕城南 提交于 2020-07-07 07:19:14
问题 I don't want to use getUpdates method to retrieve updates from Telegram, but a webhook instead. Error from getWebhookInfo is: has_custom_certificate: false, pending_update_count: 20, last_error_date: 1591888018, last_error_message: "SSL error {error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed}" My code is: from flask import Flask from flask import request from flask import Response app = Flask(__name__) @app.route('/', methods=['POST', 'GET']) def bot(): if

Why cannot I receive any POST request on my Telegram bot written with Flask (Python)?

a 夏天 提交于 2020-07-07 07:18:25
问题 I don't want to use getUpdates method to retrieve updates from Telegram, but a webhook instead. Error from getWebhookInfo is: has_custom_certificate: false, pending_update_count: 20, last_error_date: 1591888018, last_error_message: "SSL error {error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed}" My code is: from flask import Flask from flask import request from flask import Response app = Flask(__name__) @app.route('/', methods=['POST', 'GET']) def bot(): if

Accessing all cookies in the Flask test response

旧街凉风 提交于 2020-07-06 11:06:27
问题 After I make a request with the Flask test client, I want to access the cookies that the server set. If I iterate over response.headers , I see multiple Set-Cookie headers, but if I do response.headers["Set-Cookie"] , I only get one value. Additionally, the headers are unparsed strings that are hard to test. response = client.get("/") print(response.headers['Set-Cookie']) 'mycookie=value; Expires=Thu, 27-Jun-2019 13:42:19 GMT; Max-Age=1800; Path=/' for item in response.headers: print(item) (

How can I add python type annotations to the flask global context g?

江枫思渺然 提交于 2020-07-06 09:41:24
问题 I have a decorator which adds a user onto the flask global context g: class User: def __init__(self, user_data) -> None: self.username: str = user_data["username"] self.email: str = user_data["email"] def login_required(f): @wraps(f) def wrap(*args, **kwargs): user_data = get_user_data() user = User(user_data) g.user = User(user_data) return f(*args, **kwargs) return wrap I want the type (User) of g.user to be known when I access g.user in the controllers. How can I achieve this? (I am using

How do I send cookies with request when testing Flask applications through nosetests?

主宰稳场 提交于 2020-07-06 09:13:06
问题 I'm having some trouble sending a cookie with my test request. I've tried something like this: # First request to log in, retrieve cookie from response response = self.app_client.post('/users/login', query_string={ data.. ) cookie = response.headers['Set-Cookie'] # Contains: user_hash=3f305370487731289a7f9bd8d379a1c2; Domain=.flowdev.com; Path=/ # Second request that requires the cookie response = self.app_client.get('/users/', headers={'Set-Cookie': cookie}) # Here i print out request

How to send image to Flask server from curl request

折月煮酒 提交于 2020-07-05 08:30:18
问题 I want to send an image by curl to flask server, i am trying this curl command curl -X POST -F file=image.jpg "http://127.0.0.1:5000/" but it did not work by the way on the server side i handle the image by this code image = Image.open(request.files['file']) i am trying to read the image using PIL Is there anyway to do this? Thanks in advance 回答1: This worked for me: curl -F "file=@image.jpg" http://localhost:5000/ The '@' is important, otherwise you end up with an http error 400 (server