Assertion Error in Python Code sample

  • Last Post 17 January 2018
viji posted this 10 January 2018

I have download the sample Python code from

It's for python version 2.7, I have made necessary changes to work with python version 3.6.

But I'm getting an error with my password

Below is the line in which I'm getting error:

{ "Authorization" : "Basic %s" %("%s:%s" % base64.b64encode(bytes(self.ApplicationId,"utf-8"), bytes(self.Password,'utf-8')) ) }


The error message that I am getting is as follows: 

  File "D:\Anaconda3\lib\", line 60, in b64encode

    assert len(altchars) == 2, repr(altchars)

   AssertionError: b'Password'

Order By: Standard | Newest | Votes
Koen de Leijer posted this 11 January 2018


I/we did not have any trouble getting the samples to work in both Java (your other post) and Python,
can you provide the complete source-code (excl license information) you are using?

Best regards
Koen de Leijer

viji posted this 11 January 2018


I tried attaching the code but its throwing error saying that file format not supported.

I downloaded the code from the sample code provided( In that I have made some changes.

The changes are as follows:



In line 36:

ServerUrl = ""

In line 97:

return { "Authorization" : "Basic %s" %("%s:%s" % base64.b64encode(bytes(self.ApplicationId,"utf-8"), bytes(self.Password,'utf-8')) ) }

Instead of urllib2 package, I have used urllib3 package






Added the below line

String[] args1 = {"recognize","<path to pdf>","<path to docx>"};


In Client

Given the required credentials and proxy details.


Koen de Leijer posted this 11 January 2018


This does not seems to be an issue with your ABBYY but with your setup.
You should not encode the username/password and it's not neccessary to use URLLib or Anaconda
We use something like the following Python-snippet (using the Python requests-library):

from __future__ import absolute_import, unicode_literals

import requests
from ABBYY import CloudOCR

class ABBYYWrapper(object):

    def __init__(self, pdf_, language_='en', settings_=None):
        self._pdf = pdf_
        self._language = language_
        self._exportFormat = 'pdfSearchable'
        self._cloudurl = ""
        self._cloudapplicationid = "abbyy_cloud_id"
        self._cloudpassword = "abbyy_cloud_password"

    def perform_cloud_ocr(self):
        # set file-pointer to first byte of the file

        # create a dictionary holding  the PDF
        post_file = {'ocred_pdf':}

        # get handle to ABBYYs CloudOCR
        ocr_engine = CloudOCR(

        # override URL of ABBYYs CloudOCR
        ocr_engine.base_url = self._cloudurl

        # process the PDF and download/return the result
        result = ocr_engine.process_and_download(
        return result

viji posted this 12 January 2018


I tried the code snippet given by you. But I'm getting 401 Client error

I had given the necessary proxy settings.

The error is as follows:

 File "", line 47, in perform_cloud_ocr


  File "D:\Anaconda3\lib\site-packages\ABBYY\", line 104, in process_and_download

    task = self.processImage(file=file, **kwargs)

  File "D:\Anaconda3\lib\site-packages\ABBYY\", line 20, in processImage

    return self._postfile('processImage', file, **kwargs).pop()

  File "D:\Anaconda3\lib\site-packages\ABBYY\", line 60, in _postfile

    return self._process_reply(reply)

  File "D:\Anaconda3\lib\site-packages\ABBYY\", line 68, in _process_reply


  File "D:\Anaconda3\lib\site-packages\requests\", line 935, in raise_for_status

    raise HTTPError(http_error_msg, response=self)

requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url:

Koen de Leijer posted this 12 January 2018


Please check your credentials (abbyy_cloud_id and abbyy_cloud_password)

Best regards

Koen de Leijer

viji posted this 17 January 2018


I have checked my credentials and that is right. But still I'm getting the below error:

  HTTPError: 401 Client Error: Unauthorized for url:


Oksana Serdyuk posted this 17 January 2018

Please send us to the logs from the Fiddler debugger (you can download the Fiddler debugger for free here: