#coding=utf-8 import urllib2 import json body = { "id":123456, "index":"indexName" } url = "http://www.baidu.com" head = { "Content-Type":"application/json" } # 发送post请求 request = urllib2.Request(url,json.dumps(body),head) # 发送get请求 # request = urllib2.Request(url) response = urllib2.urlopen(request,None,3000) data = response.read() print(data)