You are requesting a WSGI environment using length = int(env.get('CONTENT_LENGTH', 0)) (forum.py:68). I just ran an example WSGI server (sample code taken from python docs) that returns all available environment variables on request:
from wsgiref.util import setup_testing_defaults from wsgiref.simple_server import make_server
The output that I get when I request a test server (among many other variables):
SERVER_PORT: 8000 CONTENT_LENGTH: GLADE_CATALOG_PATH: :
You see that the variable CONTENT_LENGTH is empty. This is similar to your application.
If now env-dictionary is requested using env.get('CONTENT_LENGTH', 0) , CONTENT_LENGTH-key , but this value is an empty string, so the get () method returns '' and the default value of 0 is not specified by you.
Since an empty string cannot be converted to int, you get a ValueError value.
Try to catch the exception and your code should work:
try: length = int(env.get("CONTENT_LENGTH", 0)) except ValueError: length = 0
source share