python help api dont work

  • 477 Views
  • Last Post 28 December 2015
easy-send posted this 24 December 2015

i need help with may code request send 400 bad request

APPID = "*" APPPASSWORD = "***" URL = "https://cloud.ocrsdk.com/processImage"

def send(): to_encode = APPID + ":" + APPPASSWORD iso_encoding = to_encode.encode("iso-8859-1") base = base64.b64decode(iso_encoding)

base_header = {"Authorization": "Basic " + base}

r = requests.post(URL, files={'photo.jpg': open('photo.jpg', 'rb')},
                  json=json.dumps({"language": "Hebrew", "textType": "normal", "exportFormat": "txt"}),
                  headers=base_header)

response_xml = r.content

print response_xml

return "ok"

IvanPopov posted this 28 December 2015

Hi,

In this case you actually want to get a base64-encoded string, so please replace this line

base = base64.b64decode(iso_encoding)

with the following one:

base = base64.b64encode(iso_encoding)

Close