RESTFUL POST with Python request to Glassfish Server
Question: I'm having a difficulty trying to make a Python REST POST to a webservice
running on Glassfish. I have verified that POST works ok using CURL but having
no luck with Python.

**Here is the CURL request that works ok.**

    
    
    curl -X POST -H "Content-Type: application/json" -d '{"id":1,"lastname":"smith"}' 
      http://192.168.0.20:8080/field1/resources/com.field1entity.field1
    

**Here is the Python code to make the POST request**

    
    
    import urllib
    import httplib2
    
    def call():
    http = httplib2.Http()
    
    url = 'http://192.168.0.20:8080/field1/resources/com.field1entity.field1'
    
    params = urllib.urlencode({"id":11111,"lastname":"oojamalip"})
    
    response, content = http.request(url, 'POST', params, headers={'Content-type':'application/json'})
    print "lets stop here to have a looksy at the variables"                               
    print content
    
    if __name__ == '__main__':
    
    namesPage = call()
    print namesPage
    

**Output from console,**

> Unexpected character ('l' (code 108)): expected a valid value (number,
> String, array, object, 'true', 'false' or 'null') at [Source:
> org.apache.catalina.connector.CoyoteInputStream@18f494d; line: 1, column: 2]

Hope someone can shed some light on the problem.

thanks Nick


Answer: You are url encoding the prams and then telling the server it is json encoded

    
    
    import json
    
    params = json.dumps({"id":11111,"lastname":"oojamalip"})
    # then
    response, content = http.request(url, 'POST', body=params, headers={'Content-type':'application/json'})
    

