im starting with python and web.py
im trying to build a REST api with it. i know hoy to use the basics of web.py but i still can figure a way to get the Content-Type of a request i got this post function defined:
def POST(self,name):
ct=web.ctx.env.get('Content-Type')
return json.dumps({ 'body' : web.data(),'ct':ct } )
im trying to get the body data and the content type bit ct ends null
curl -H 'Accept: application/json' localhost:8080/test -d '{"a":"b"}' -H "Content-Type: application/json"
outputs
{"body": "{\"a\":\"b\"}", "ct": null}
thanks in advance
The web.ctx.env
structure gives you access to the WSGI environment variable. In WSGI apps, the content type header is named CONTENT_TYPE
:
ct = web.ctx.env.get('CONTENT_TYPE')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With