Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnboundLocalError: local variable 'res' referenced before assignment #81

Open
aylitat opened this issue Dec 17, 2024 · 4 comments
Open
Labels
bug Something isn't working

Comments

@aylitat
Copy link

aylitat commented Dec 17, 2024


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
Copy link
Author

aylitat commented Dec 17, 2024

`# 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

@FrancescoMasaia
Copy link

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

@balagrivine
Copy link

@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

@gagb gagb added the bug Something isn't working label Dec 17, 2024
@sidesteps
Copy link

same as #40

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants