python - http.server: decoding POST request to JSON -


i'm writing simple http-server based on http.server (using python-3)

the client supposed send json-object via post.

payload={'text': 'bi ba buzemann!',          'nouns': ['streetlight', 'situation'],          'states': ['solid', 'fluid']         } requests.post(url, data=payload) 

this arrives fine @ server, in serializd form

def do_post(self:   length = self.headers['content-length']   data = self.rfile.read(int(length))   # b'states=solid&states=fluid&nouns=oracle&text=bi+ba+buzemann%21' 

now question is: how turn urlencoded result dict (or intermediate json)?

do have manually, in:

for x in str(r).split('&'):    y,z=x.split('=')    if not y in d:       d[y]=[]    d[y]+=[urllib.parse.unquote_plus(z)] 

or there well-debugged function available in common module?

if can change request, send in json:

import json payload={'text': 'bi ba buzemann!',          'nouns': ['streetlight', 'situation'],          'states': ['solid', 'fluid']         } requests.post(url, data=json.dumps(payload)) 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -