title: How do I do a basic REST Post with Requests in Python?
body: <p>I am having trouble using <a href="http://docs.python-requests.org/en/latest/" rel="nofollow">Requests</a></p>
  
  <p>The API I am testing indicates the parameter device_info to be POSTED in the message body. It also says that the device_info as a form field. In all the documentation for <a href="http://docs.python-requests.org/en/latest/" rel="nofollow">Requests</a> I cannot find how to add a "name" to the parameter other than slap the name with it's value in json. Here is what I have tried.</p>
  
  <pre><code>import requests
  import json
  
  loginPayload = {'device_info':{'app-id':'fc','os-type':'ios'}}
  loginHeaders = {'content-type': 'application/json','Authorization':'Basic base64here'}
  loginUrl = "http://subdomain.test.com/endpoint/method"
  loginPost = requests.post(loginUrl, params=json.dumps(loginPayload), headers=loginHeaders)
  
  print loginPost.text
  </code></pre>
  
  <p>I have tried changing <code>params=</code> to <code>data=</code> but I've had no luck. </p>
  
  <p>The response back I'm getting is:</p>
  
  <pre><code>{
  "response": {
  "message": "Parameter 'device_info' has invalid value ()", 
  "code": 400, 
  "id": "8c4c51e4-9db6-4128-ad1c-31f870654374"
    }
  }
  </code></pre>
  
  <p>EDITED:</p>
  
  <p>Getting somewhere new! I have no modified my code to look as follows:</p>
  
  <pre><code>import requests
  
  login = 'test'
  password = 'testtest'
  url = "http://subdomain.domain.com/endpoint/method"
  
  authentication = (login,password)
  payload = {'device_info': {'device_id': 'id01'}}
  request = requests.post(url, data=payload, auth=authentication)
  
  print request.text
  </code></pre>
  
  <p>Which produces:</p>
  
  <pre><code>{
    "response": {
      "message": "Parameter 'device_info' has invalid value (device_id)", 
      "code": 400, 
      "id": "e2f3c679-5fca-4126-8584-0a0eb64f0db7"
    }
  }
  </code></pre>
  
  <p>What seems to be the the issue? Am I not submitting it in the required format?</p>
  
  <p>EDITED: The solution was changing my parameters to: </p>
  
  <pre><code>{
      "device_info": "{\"app-id\":\"fc\",\"os-type\":\"ios\",\"device_id\":\"myDeviceID1\"}"
  }
  </code></pre>