Ejemplo n.º 1
0
def myRequest_get(http_url, params, save_file=""):
    params["app_id"] = APP_ID
    params["app_key"] = APP_KEY
    response = requests.get(http_url, params=params)
    print(response)
    req_con = response.content.decode('utf-8')
    try:
        req_dict = JSONDecoder().decode(req_con)
        print(req_dict)
        save(save_file, req_dict)
        return req_dict
    except:
        return {}
Ejemplo n.º 2
0
def myRequest(http_url, data, filepath="", save_file=""):
    headers = HEADERS
    if filepath != "":
        img = open(filepath, 'rb')
        img = base64.b64encode(img.read())
        data["image"] = img
        response = requests.post(http_url, data=data, headers=headers)
    else:
        response = requests.post(http_url, data=data, headers=headers)
    req_con = response.content.decode('utf-8')
    req_dict = JSONDecoder().decode(req_con)
    print(req_dict)
    save(save_file, req_dict)
    return req_dict
Ejemplo n.º 3
0
def myRequest( http_url, data, filepath="", save_file=""):
    data["api_key"] = API_KEY
    data["api_secret"] = API_SECRET
    if filepath != "":
        img = open(filepath, 'rb')
        files = {"img_file": img}
        response = requests.post(http_url, data=data, files=files)
    else:
        response = requests.post(http_url, data=data)
    req_con = response.content.decode('utf-8')
    req_dict = JSONDecoder().decode(req_con)
    print(req_dict)
    save(save_file, req_dict)
    return req_dict
Ejemplo n.º 4
0
def myRequest( http_url, data, filepath="", save_file=""):
    data["api_key"] = API_KEY
    data["api_secret"] = API_SECRET
    if filepath != "":
        img = open(filepath, 'rb')
        img = base64.b64encode(img.read())
        data["image_base64"] = img
        response = requests.post(http_url, data=data)
    else:
        response = requests.post(http_url, data=data)
    req_con = response.content.decode('utf-8')
    req_dict = JSONDecoder().decode(req_con)
    print(req_dict)
    save(save_file, req_dict)
    return req_dict
Ejemplo n.º 5
0
def myRequest(http_url, data, filepath="", save_file=""):
    if filepath != "":
        img = open(filepath, 'rb')
        img = base64.b64encode(img.read())
        data["content"] = img
    headers = {"Authorization": getAuthorzation(http_url, data)}
    response = requests.post(http_url, data=data, headers=headers)
    print(response)
    try:
        req_con = response.content.decode('utf-8')
        req_dict = JSONDecoder().decode(req_con)
        print(req_dict)
        save(save_file, req_dict)
        return req_dict
    except:
        return {}
Ejemplo n.º 6
0
def myRequest(http_url, data, filepath="", save_file=""):
    data["app_id"] = APP_ID
    data["app_key"] = APP_KEY
    if filepath != "":
        img = open(filepath, 'rb')
        img = base64.b64encode(img.read())
        data["img"] = img
        response = requests.post(http_url, data=data)
    else:
        response = requests.post(http_url, data=data)
    print(response)
    req_con = response.content.decode('utf-8')
    try:
        req_dict = JSONDecoder().decode(req_con)
        print(req_dict)
        save(save_file, req_dict)
        return req_dict
    except:
        return {}
Ejemplo n.º 7
0
def myRequest(http_url, data, filepath="", save_file=""):
    if filepath != "":
        img = open(filepath, 'rb')
        #img = base64.b64encode(img.read())

        #data["image"] = img.read().decode()
        #img = cv2.imread(filepath)
        files = {"image": img}
        response = requests.post(http_url, files=files, headers=HEADERS1)
    else:
        response = requests.post(http_url, data=data, headers=HEADERS2)
    try:
        req_con = response.content.decode('utf-8')
        req_dict = JSONDecoder().decode(req_con)
        print(req_dict)
        save(save_file, req_dict)
        return req_dict
    except:
        return {}
Ejemplo n.º 8
0
def myRequest2(http_url, data, filepath1, filepath2, save_file=""):
    data["appid"] = APPID
    img1 = open(filepath1, 'rb')
    #img1 = base64.b64encode(img1.read())
    img2 = open(filepath2, 'rb')
    #img2 = base64.b64encode(img2.read())
    files = {"imageA": img1, "imageB": img2}
    response = requests.post(http_url,
                             data=data,
                             files=files,
                             headers=HEADERS1)
    print(response)
    try:
        req_con = response.content.decode('utf-8')
        req_dict = JSONDecoder().decode(req_con)
        print(req_dict)
        save(save_file, req_dict)
        return req_dict
    except:
        return {}