test

Posted lulipro

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了test相关的知识,希望对你有一定的参考价值。

# -*- coding: utf-8 -*-
import urllib2,json
import urllib
import time

http_url=https://api-cn.faceplusplus.com/facepp/v3/compare
key = "iMP75CfbxCNQW4_DQkuEyW1F7ACFAZuN"
secret = "DI0ORfbskcQLs0hRhyLN60OXo_7WYoP8"

def getFaceInfo(file1path,file2path):
    # boundary是 :---------本地运行时时间
    boundary = ----------%s % hex(int(time.time() * 1000))

    data = []
    data.append(--%s % boundary)
    data.append(Content-Disposition: form-data; name="%s"\r\n % api_key)
    data.append(key)
    data.append(--%s % boundary)
    data.append(Content-Disposition: form-data; name="%s"\r\n % api_secret)
    data.append(secret)

    # 请求参数,图片的添加
    data.append(--%s % boundary)
    fr1 = open(file1path, rb)
    data.append(Content-Disposition: form-data; name="%s"; filename=" " % image_file1)
    data.append(Content-Type: %s\r\n % application/octet-stream)
    data.append(fr1.read())
    fr1.close()

    data.append(--%s % boundary)
    fr2 = open(file2path, rb)
    data.append(Content-Disposition: form-data; name="%s"; filename=" " % image_file2)
    data.append(Content-Type: %s\r\n % application/octet-stream)
    data.append(fr2.read())
    fr2.close()
    data.append(--%s--\r\n % boundary)

    http_body = \r\n.join(data)
    # buld http request
    req = urllib2.Request(http_url)
    # header
    req.add_header(Content-Type, multipart/form-data; boundary=%s % boundary)
    req.add_data(http_body)
    try:
        # req.add_header(‘Referer‘,‘http://remotserver.com/‘)
        # post data to server
        resp = urllib2.urlopen(req, timeout=5)
        # get response
        qrcont = resp.read()
        # print(qrcont)
        info = json.loads(qrcont)
        confidence = info[confidence]
        print(confidence)

    except urllib2.HTTPError as e:
        print(e.read())

file1path = r"D:\3.jpg"
file2path = r"D:\4.jpg"
getFaceInfo(file1path,file2path)

 

以上是关于test的主要内容,如果未能解决你的问题,请参考以下文章

webstorm代码片段的创建

json [test snippet]这是一个测试片段#test

java代码在片段活动中不起作用

csharp c#test片段

这两个代码片段之间有区别吗?如果有,那又如何? [复制]

片段中ListView的setOnItemClickListener