POST JSON with python and reading response
Question: I am trying to make a post request in python and I believe I am doing
everything correct. However it is not returning any response. I can't seem to
figure out if there is anything wrong with my request. It seems like there may
be something wrong with the service if I am not getting any response back. Is
there anything inherently wrong with what I've written here?

    
    
    import json
    import urllib2
    
    data = {'first_name': 'John','last_name': 'Smith','email': 'johnsmith@smith.com','phone': '215-555-1212'}
    
    req = urllib2.Request('https://someurl.io/')
    req.add_header('Content-Type', 'application/json')
    
    response = urllib2.urlopen(req, json.dumps(data))
    print response.read()
    print response.headers
    


Answer: Honestly, unless you love urllib2, I suggest using
[requests](http://docs.python-requests.org/en/latest/). Here's the same data
code in requests:

    
    
    import requests
    import json
    
    payload = {'first_name': 'John','last_name': 'Smith','email': 'johnsmith@smith.com','phone': '215-555-1212'}
    url = 'https://someurl.io/'
    
    r = requests.post(url, json=json.dumps(payload))
    
    print r.content
    print r.headers
    

