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

Can't send PDF in-memory or local pdf file via LetterEditable / LettersApi #211

Open
vaughnkoch opened this issue Jul 25, 2024 · 0 comments

Comments

@vaughnkoch
Copy link

vaughnkoch commented Jul 25, 2024

Hi, I'm trying to send a simple PDF file using the Lob Python SDK, but I'm running into errors. The key issue seems to be that the file param of LetterEditable will only accept a Python str value, which doesn't allow for in-memory PDFs.
It also does not upload local files like the API documents say it should. Uploading raw HTML works, but we need to upload PDF files.

Ideally I would like to pass an in-memory file, e.g. bytes or io.BytesIO. Here's what I see when I try to pass that:

lob_python.exceptions.ApiTypeError: Invalid type for variable 'file'. Required value type is str and passed type was bytes at ['file']

That error is being generated in lob_python, letter_editable.py:362:

self.file = file

because on line 120:

'file': (str,), # noqa: E501

and this is enforced via __setitem__ in ModelNormal and set_attribute in OpenApiModel.

Notes:

  • See this gist to see the failures: https://gist.github.com/vaughnkoch/7a727dfc066cd4f6d7b8986960208c7b
  • Suggestion: create a file_upload_type parameter, that would accept 'file-like-stream', 'html', 'url', etc. Then allow each of those in the file parameter.
  • I'm using python 3.12.3 and lob_python====5.1.3.
  • I've already brought this up with Lob support, who suggested I open this issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant