tomcat - How to properly write a python cgi script that receives json data? -



tomcat - How to properly write a python cgi script that receives json data? -

my current test python script like:

#!/usr/bin/env python import sys info = sys.stdin.read() myjson = json.loads(data)

the problem if worked in case, on others seems block, @ read().

for other reasons forced utilize tomcat cgi scripts, not sure if matters anyway.

you'll need check content length before reading , limit number of byte read sys.stdin.read(). see cgi.parse_header().

update:

your incoming info comes through environment populated web server. accessible in os.environ.

import os cgi import parse_header os.environ['content-type'] = 'text/html; charset=utf-8' parse_header(os.environ['content-type']) # returns ('text/html', {'charset': 'utf-8'})

so in cgi script need (roughly):

import os, cgi, sys cl, _ = parse_header(os.environ['content-length']) info = sys.stdin.read(int(cl))

python tomcat cgi

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -