'What is the error of tesseract.image to osd?

I am writing a telegram bot that, when receiving an image based on text, would set the correct orientation of the picture. I wrote a function for rotation, the code is attached, I used tesseract, but the bot regularly throws an error if psm = 0 or invalid resolution is not specified, if psm = 3, [Errno 2] no such file in directory: ...\tess_*****.osd. Considering that the only place where osd is used is the rotation function, I think the error is somewhere here, how do I fix it?

def rotate(image, center=None, scale=1.0):
    config = '--psm 3 -c min_characters_to_try=1'
    angle = 360 - int(re.search('(?<=Rotate: )\d+', pytesseract.image_to_osd(image, config=config)).group(0))
    (h, w) = image.shape[:2]
    if center is None:
        center = (w / 2, h / 2)
    matrix = cv2.getRotationMatrix2D(center, angle, scale)
    return cv2.warpAffine(image, matrix, (w, h))


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source