import base64
import json
import requests


def base64_api(uname, pwd, img):
    with open(img, 'rb') as f:
        base64_data = base64.b64encode(f.read())
        b64 = base64_data.decode()
    data = {"username": uname, "password": pwd, "typeid": 27, "image": b64}
    result = json.loads(requests.post("http://api.ttshitu.com/imageXYPlus", json=data).text)
    if result['success']:
        return result["data"]["result"]
    else:
        return result["message"]
