当前位置: 首页>>代码示例>>Python>>正文


Python Request.json方法代码示例

本文整理汇总了Python中requests.Request.json方法的典型用法代码示例。如果您正苦于以下问题:Python Request.json方法的具体用法?Python Request.json怎么用?Python Request.json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在requests.Request的用法示例。


在下文中一共展示了Request.json方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from requests import Request [as 别名]
# 或者: from requests.Request import json [as 别名]
def main(args):
    if len(args) != 1:
       print "Usage monitor.py [number of entries to retrieve]"
       sys.exit(1)
    elif args[0].isdigit() == False:
       print "Usage monitor.py [number of entries to retrieve]"
       sys.exit(1)
    offset = int(args[0])
    operation = 'ct/v1/get-sth'
    url = 'http://ct.googleapis.com/aviator/{}'.format(operation)
    
    s = Session()
    r = Request('GET', url)
    
    prepped = r.prepare()
    
    r = s.send(prepped)
    
    numcerts = 0
    
    if r.status_code == 200:
        sth = r.json()
        numcerts = sth['tree_size']
    
    operation = 'ct/v1/get-entries'
    url = 'http://ct.googleapis.com/aviator/{}'.format(operation)
    
    endindex = numcerts - 1
    startindex = numcerts - offset
    
    params = urllib.urlencode({'start':startindex,'end':endindex})
    
    
    s = Session()
    
    r = Request('GET',
                 '{}?{}'.format(url,params),
                 )
    
    prepped = r.prepare()
    
    r = s.send(prepped)
    
    if r.status_code == 200:
        entries = r.json()['entries']
        for i in entries:
            print "End entity cert"
            parse_leafinput(base64.b64decode(i['leaf_input']))
            print "Signing cert chain"
            parse_asn1certs(base64.b64decode(i['extra_data']))
    else:
        print r.status_code
        print r.text
开发者ID:konklone,项目名称:CTPyClient,代码行数:55,代码来源:monitor.py

示例2: main

# 需要导入模块: from requests import Request [as 别名]
# 或者: from requests.Request import json [as 别名]
def main(args):
    if len(args) <= 1:
       print "Usage getentries.py startindex endindex"
       sys.exit(1)
    elif args[0].isdigit() == False or args[1].isdigit() == False:
       print "Usage getentries.py startindex endindex" 
       sys.exit(1)
    startindex = int(args[0])
    endindex = int(args[1])
    
    operation = 'ct/v1/get-entries'
    url = 'http://ct.googleapis.com/aviator/{}'.format(operation)
    
    
    params = urllib.urlencode({'start':startindex,'end':endindex - 1})
    
    s = Session()
    r = Request('GET',
    '{}?{}'.format(url,params),
    )
    
    prepped = r.prepare()
    r = s.send(prepped)
    if r.status_code == 200:
	entries = r.json()['entries']
	print entries
    else:
	print r.status_code
	print r.text
开发者ID:Phracks,项目名称:CTPyClient,代码行数:31,代码来源:getentries.py

示例3: encode

# 需要导入模块: from requests import Request [as 别名]
# 或者: from requests.Request import json [as 别名]
    def encode(self, onem2m_primitive):
        """
        Encodes OneM2M JSON primitive object to Tx specific HTTP message
        with JSON content type
        """

        params = onem2m_primitive.get_parameters()
        proto_params = onem2m_primitive.get_protocol_specific_parameters()

        # This is Tx encoder so we use Request
        msg = Request()

        if params:
            # Method (Operation)
            if OneM2M.short_operation in params:
                msg.method = self._encode_operation(params[OneM2M.short_operation])

            # URL
            if OneM2M.short_to in params:
                resource_uri = self._translate_uri_from_onem2m(params[OneM2M.short_to])
                entity_address = ""
                if proto_params:
                    if protocol_address in proto_params:
                        entity_address = proto_params[protocol_address]
                        if protocol_port in proto_params:
                            entity_address += (":" + str(proto_params[protocol_port]))

                msg.url = "http://" + entity_address + resource_uri

            # encode headers and query parameters
            delimiter = "?"
            for key, value in params.items():

                # Query parameters
                if msg.url and key in http_query_params:
                    msg.url += (delimiter + key + "=" + str(value))
                    delimiter = "&"
                    continue

                # Headers from primitive parameters
                encoded = http_headers.encode_default_ci(key, None)
                if None is not encoded:
                    msg.headers[encoded] = str(value)

        # Headers from protocol specific parameters
        if proto_params:
            for key, value in proto_params.items():
                encoded = http_headers.encode_default_ci(key, None)
                if None is not encoded:
                    msg.headers[encoded] = str(value)

        # Body (content)
        content = onem2m_primitive.get_content()
        if content:
            msg.json = content
        return msg.prepare()
开发者ID:ljakab,项目名称:integration-test,代码行数:58,代码来源:onem2m_http.py

示例4: Session

# 需要导入模块: from requests import Request [as 别名]
# 或者: from requests.Request import json [as 别名]


url = 'http://ct.googleapis.com/aviator/ct/v1/get-roots'


s = Session()
r = Request('GET',
             url)

prepped = r.prepare()

r = s.send(prepped)

if r.status_code == 200:
   roots = r.json()

# RFC 6962 defines the certificate objects as base64 encoded certs.
# Importantly, these are not PEM formatted certs but base64 encoded
# ASN.1 (DER) encoded

for i in roots:
   certs = roots[i]
   for k in certs:
       try:
           certobj = crypto.load_certificate(crypto.FILETYPE_ASN1,base64.b64decode(k))
           subject = certobj.get_subject()
           print 'CN={},OU={},O={},L={},S={},C={}'.format(subject.commonName,
                                                      subject.organizationalUnitName,
                                                      subject.organizationName,
                                                      subject.localityName,
开发者ID:Phracks,项目名称:CTPyClient,代码行数:32,代码来源:fetchroots.py

示例5: main

# 需要导入模块: from requests import Request [as 别名]
# 或者: from requests.Request import json [as 别名]
def main(args):
    autofetch = True
    first = 0
    second = 0

    if len(args) < 1:
       print "Usage monitor.py \"path to log public key\" [sth treesize 1] [sth treesize 2]"
       sys.exit(1)
    elif len(args) > 1:
	autofetch = False
	first = args[1]
	second = args[2]

    logkeypath = args[0]

    if autofetch == True:
        operation = 'ct/v1/get-sth'
	url = 'http://ct.googleapis.com/aviator/{}'.format(operation)
    
	s = Session()
	r = Request('GET', url)
	prepped = r.prepare()
	proxies = {
		#"http": "http://127.0.0.1:8080",
	}
	r = s.send(prepped,proxies=proxies)
    
	numcerts = 0
    
	if r.status_code == 200:
	    sth = r.json()
	    numcerts = sth['tree_size']

	logkey = open(logkeypath,'r').read()
	if verify_sth(sth,logkey) == False:
	    print 'Invalid log; signed tree head failed validation'
	    return 1
	else:
	    sth1 = sth

	# Get another STH, keep asking until we get another one different
	cacheval = re.search('\d+',r.headers['cache-control']).group(0)
	fetchct = 1
	delayval = 1

	while True:
	    time.sleep(int(cacheval))
	    print "STH fetch # {0}".format(fetchct)
	    fetchct += 1
	    r = s.send(prepped,proxies=proxies)
	    if r.status_code == 200:
		sth = r.json()
		if verify_sth(sth,logkey) == False:
		    print 'Invalid log; signed tree head failed validation'
		    return 1
		else:
		    sth2 = sth
		    delayval = int(math.log(fetchct))
		if sth1['timestamp'] != sth2['timestamp']:
		    break
	first = sth1['treesize']
	second = sth1['treesize']

    # Verify STHs by fetching consistency proof

    operation = 'ct/v1/get-sth-consistency'
    url = 'http://ct.googleapis.com/aviator/{}'.format(operation)
    s = Session()
    params = urllib.urlencode({'first':first,'second':second})
    r = Request('GET', '{}?{}'.format(url,params))
    prepped = r.prepare()
   
    r = s.send(prepped)
    if r.status_code == 200:
	print r.text
开发者ID:Phracks,项目名称:CTPyClient,代码行数:77,代码来源:monitor.py


注:本文中的requests.Request.json方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。