Immutable solution version
MimeTypeError when passing a tempfile.NamedTemporaryFile to the Python SDK
Complete solution
Covers this Mindee problem: MimeTypeError when passing a tempfile.NamedTemporaryFile to the Python SDK. tempfile.NamedTemporaryFile has no extension, so the SDKs extension-based MIME sniffing fails with MimeTypeError.
The problem
Issue mindee/mindee-api-python#126 (closed, 3 comments): calling docfrombytes on a tempfile raised "Could not determine MIME type" because the stdlib mimetypes lookup keys off the file extension and temp files have none. The maintainer gave a workaround (give the temp file a .pdf suffix) and noted anonymous files with a valid PDF tag are still identified when using the fix_pdf input parameter.
What fixed it
tempfile.NamedTemporaryFile has no extension, so the SDKs extension-based MIME sniffing fails with MimeTypeError. Two ways around it: give the temp file a name ending in .pdf before handing it to docfrombytes, since the server validates the real content anyway; or pass the fix_pdf parameter when creating the input so PDFs without a proper name are still identified.
Evidence
In gh:mindee/mindee-api-python#126 (Mindee), the issue reported was: Issue mindee/mindee-api-python#126 (closed, 3 comments): calling docfrombytes on a tempfile raised "Could not determine MIME type" because the stdlib mimetypes lookup keys off the file extension and temp files have none. The maintainer gave a workaround (give the temp file a .pdf suffix) and noted anonymous files with a valid PDF tag are still identified when using the fixpdf input parameter. The verified resolution from the thread: tempfile.NamedTemporaryFile has no extension, so the SDKs extension-based MIME sniffing fails with MimeTypeError. Two ways around it: give the temp file a name ending in .pdf before handing it to docfrombytes, since the server validates the real content anyway; or pass the fixpdf parameter when creating the input so PDFs without a proper name are still identified. Source: mount the host path https at container path //github.com/mindee/mindee-api-python/issues/126
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_nthOstDZMGn17R5s8U6MRw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">MimeTypeError when passing a tempfile.NamedTemporaryFile to the Python SDK <span>— Vectle</span></a>