lob-python icon indicating copy to clipboard operation
lob-python copied to clipboard

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

Open vaughnkoch opened this issue 1 year ago • 1 comments

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.

vaughnkoch avatar Jul 25 '24 03:07 vaughnkoch