Issue with Python API Call for OCR Space

Hey everyone!

I am having an issue using python to OCR local documents. I’ve tested everything on Postman, which works great. When I go to copy the code into Python is where the errors happen. Hopefully you can help.

The code I’m using:

> import http.client

conn = http.client.HTTPSConnection("api.ocr.space")

payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"C:\OCR\blah.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"filetype\"\r\n\r\njpg\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"isOverlayRequired\"\r\n\r\ntrue\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"iscreatesearchablepdf\"\r\n\r\nfalse\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"issearchablepdfhidetextlayer\"\r\n\r\nfalse\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"OCREngine\"\r\n\r\n2\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"scale\"\r\n\r\ntrue\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"isTable\"\r\n\r\ntrue\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"

headers = {
    'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
    'apikey': "32f65b963c88957",
    'cache-control': "no-cache",
    'postman-token': "30dea345-a747-d55b-cb9f-14b77bb8bea5"
    }

conn.request("POST", "/parse/image", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))

The error I’m getting is

{“OCRExitCode”:99,“IsErroredOnProcessing”:true,“ErrorMessage”:[“Some internal processing error occurred. Please give us some time, we are looking into this!”],“ErrorDetails”:“”,“ProcessingTimeInMilliseconds”:“0”}

Not really sure where to go from here. Again, works well in the Postman app.

If it works in Postman, you can use the code export feature.