werkzeug

Serverless WSGI Local Server Running Slow

Serverless WSGI Local Server Running Slow Question: Im using the node package serverless-wsgi 1.4.9 to serve the routes of my serverless framework application When I run by dev server serverless wsgi serve I’m having problems with the requests taking a long time (10seconds – 1min) to return a response in chrome. To avoid hitting a …

Total answers: 1

Running Flask raises "WinError 10038"

Running Flask raises "WinError 10038" Question: Running a simple Flask app raises OSError: [WinError 10038] An operation was attempted on something that is not a socket. The page is not served in the browser. What does the error mean? How do I fix it? from flask import Flask, render_template app = Flask(__name__) @app.route(‘/’) def index(): …

Total answers: 2

Flask – how to write werkzeug logs to log file using RotatingFileHandler?

Flask – how to write werkzeug logs to log file using RotatingFileHandler? Question: I’ve found some somewhat similar questions, but nothing that directly addresses this. I’m trying to output all Werkzeug logging to a log file. I can get part of the logging to output to the file, but I cannot seem to capture any …

Total answers: 3

How to apply integration tests to a Flask RESTful API

How to apply integration tests to a Flask RESTful API Question: [As per https://stackoverflow.com/a/46369945/1021819, the title should refer to integration tests rather than unit tests] Suppose I’d like to test the following Flask API (from here): import flask import flask_restful app = flask.Flask(__name__) api = flask_restful.Api(app) class HelloWorld(flask_restful.Resource): def get(self): return {‘hello’: ‘world’} api.add_resource(HelloWorld, ‘/’) …

Total answers: 5

Check if Flask request context is available

Check if Flask request context is available Question: I want to log some data from context variables (request, session) when logging during a Flask request, but use default behavior if not. I’m using a try … except block in logging.formatter. Is there a better way to check for a request context? try: record.user = session[‘user_name’] …

Total answers: 1

RuntimeError: working outside of application context

RuntimeError: working outside of application context Question: app.py from flask import Flask, render_template, request,jsonify,json,g import mysql.connector app = Flask(__name__) **class TestMySQL():** @app.before_request def before_request(): try: g.db = mysql.connector.connect(user=’root’, password=’root’, database=’mysql’) except mysql.connector.errors.Error as err: resp = jsonify({‘status’: 500, ‘error’: “Error:{}”.format(err)}) resp.status_code = 500 return resp @app.route(‘/’) def input_info(self): try: cursor = g.db.cursor() cursor.execute (‘CREATE TABLE …

Total answers: 4

AttributeError: 'Context' object has no attribute 'wrap_socket'

AttributeError: 'Context' object has no attribute 'wrap_socket' Question: I am trying to set up a Flask server that uses an OpenSSL context. However, since I moved the script on a different server, it keeps throwing the following error, no matter if I am using Python 2.7 or 3.4 and no matter which SSL method I …

Total answers: 1

Flask change the server header

Flask change the server header Question: I’ve made a simple flask application: Trying 127.0.0.1… Connected to localhost. Escape character is ‘^]’. GET / HTTP/1.1 host:google.be HTTP/1.0 404 NOT FOUND Content-Type: text/html Content-Length: 233 Server: Werkzeug/0.9.6 Python/2.7.6 Date: Mon, 08 Dec 2014 19:15:43 GMT <!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 3.2 Final//EN”> <title>404 Not Found</title> <h1>Not Found</h1> …

Total answers: 6

X-Forwarded-Proto and Flask

X-Forwarded-Proto and Flask Question: I have precisely the same problem described in this SO question and answer. The answer to that question is a nice work around but I don’t understand the fundamental problem. Terminating SSL at the load balancer and using HTTP between the load balancer and web/app servers is very common. What piece …

Total answers: 1