5

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

asked Mar 13, 2013 at 19:15

1 Answer 1

9

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')
answered Mar 13, 2013 at 19:18
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.