python request 发送json数据_json

python request 发送json数据_python_02

python request 发送json数据_django_03

python request 发送json数据_json_04


# !/usr/bin/env python

# -*- coding: utf-8 -*-

import urllib2

import urllib

import cookielib

import json

import httplib

import re

import requests

s=requests.session()

#response = s.post(url, params=datas, **kwargs)

headers = {'Content-Type': 'application/json'}    ## headers中添加上content-type这个参数,指定为json格式

datas={

"title":"Elasticsearch test",

"name" :{  "first":"zhao",  "last":"zhoucui"  },

"publish_date":"2017-11-29",

"price":"1000"  }

response = s.post('http://192.168.137.2:9200/library/books/3000',headers=headers, data=json.dumps(datas))

print response.text





C:\Python27\python.exe C:/Users/TLCB/PycharmProjects/untitled/mycompany/Django/a16.py

{"_index":"library","_type":"books","_id":"3000","_version":8,"_shards":{"total":2,"successful":1,"failed":0},"created":true}



Process finished with exit code 0