markitdown icon indicating copy to clipboard operation
markitdown copied to clipboard

UnboundLocalError: local variable 'res' referenced before assignment

Open aylitat opened this issue 1 year ago • 5 comments


UnboundLocalError Traceback (most recent call last) in <cell line: 4>() 2 3 markitdown = MarkItDown() ----> 4 result = markitdown.convert("/content/TEST.pdf") 5 print(result.text_content)

2 frames /usr/local/lib/python3.10/dist-packages/markitdown/_markitdown.py in _convert(self, local_path, extensions, **kwargs) 1043 error_trace = ("\n\n" + traceback.format_exc()).strip() 1044 -> 1045 if res is not None: 1046 # Normalize the content 1047 res.text_content = "\n".join(

UnboundLocalError: local variable 'res' referenced before assignment

aylitat avatar Dec 17 '24 04:12 aylitat

`# If we hit an error log it and keep trying try: res = converter.convert(local_path, **_kwargs) except Exception: error_trace = ("\n\n" + traceback.format_exc()).strip()

            if res is not None:
                # Normalize the content
                res.text_content = "\n".join(
                    [line.rstrip() for line in re.split(r"\r?\n", res.text_content)]
                )
                res.text_content = re.sub(r"\n{3,}", "\n\n", res.text_content)

                # Todo
                return res`

maybe here should some fix

aylitat avatar Dec 17 '24 04:12 aylitat

I'm also experiencing this error not on every pdf but just on some of them, and it doesn't finish the conversion to md file

FrancescoMasaia avatar Dec 17 '24 10:12 FrancescoMasaia

@aylitat I'm getting the same error above.

I have a FastAPI application utilizing markitdown through the MarkItDown API. My endpoint receives a pdf file and should be processed by markitdown. Not sure where the exact problem really lies

balagrivine avatar Dec 17 '24 15:12 balagrivine

same as #40

sidesteps avatar Dec 18 '24 16:12 sidesteps

same as #40

sorry, why is this still open if this was merged ?

obar1 avatar Mar 20 '25 08:03 obar1