urllib2 and json

后端 未结 6 700
北恋
北恋 2020-11-29 00:58

can anyone point out a tutorial that shows me how to do a POST request using urllib2 with the data being in JSON format?

6条回答
  •  一整个雨季
    2020-11-29 01:38

    To read json response use json.loads(). Here is the sample.

    import json
    import urllib
    import urllib2
    
    post_params = {
        'foo' : bar
    }
    
    params = urllib.urlencode(post_params)
    response = urllib2.urlopen(url, params)
    json_response = json.loads(response.read())
    

提交回复
热议问题