lundi 29 juin 2015

Script to send json using POST/REST and requests in python doesn't work


I'm trying to send a json in POST method using REST, but i got error:

    "Could not parse JSON data: Expecting value: line 1 column 1 
    (char 0)", "status": 500, "type": "ValueError", 
    "request": {"client_addr": "127.0.0.1", 
    "user_agent": "python-requests/2.3.0 CPython/3.4.2 Linux/3.16.0-41-generic", 
    "method": "POST", "path": "/api/adley/doc"}}
    )

I'm trying to fix, use a json.dumps or json.loads, but nothing seems to work.

I need to send one key and two values. Here is the base:

   {
metadata: {
   idx_exp: false,
   idx_exp_time: 0,
   file_ext: false,
   password: "",
   description: "base de teste",
   idx_exp_url: "",
   model: {
      item: "Text"
   },
   dt_base: "29/06/2015 14:47:10",
   name: "adley",
   id_base: 5,
   file_ext_time: 0,
   },
   content: [
   {
    field: {
          required: false,
          multivalued: false,
          alias: "Texto",
          datatype: "Text",
          name: "item",
          indices: [
               "Ordenado"
          ],
          description: "placeholder"
         }
     }
  ]
}

My to send a post script:

import requests, json
url = "http://ift.tt/1SYFCtA"
json_data = {'value':{'item':'test'}}
response = requests.post(url, params=json_data)
print(response.text)

I can't see what's wrong with my script


Aucun commentaire:

Enregistrer un commentaire