question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with binary files

See original GitHub issue

I’m trying to return an Excel file as an attachment. Here’s my code:

content_type = (
    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
)
response = HttpResponse(content=data, content_type=content_type)
response["Content-Disposition"] = 'attachment; filename="{0}"'.format(filename)
return response

First I had an encoding error:

'utf-8' codec can't decode byte 0xc0 in position 10: invalid start byte: UnicodeDecodeError
Traceback (most recent call last):
  File "/opt/apig_wsgi.py", line 44, in handler
    return response.as_apig_response()
  File "/opt/apig_wsgi.py", line 149, in as_apig_response
    response["body"] = self.body.getvalue().decode("utf-8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc0 in position 10: invalid start byte

So I activated the binary mode:

app = make_lambda_handler(application, binary_support=True)

I have no more errors but my file can’t be read 😦

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
adamchainzcommented, Mar 9, 2020

I added a few more words to the documentation to make this easier to discover in the future: 6e18125459fac889ecbf0ca2e48200a8a715577c

0reactions
adamchainzcommented, Mar 9, 2020

Aha 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Common Problems with Binary Files
Common Problems with Binary Files ... If the data is expected to fall into a known range of values, then a program can...
Read more >
A little diddy about binary file formats - BetterExplained
Binary files can get confusing. Problems happen when computers have different ways of reading data. There's something called the “NUXI” or byte-order ...
Read more >
Git is Bad at Binary File Management -- But is it Worse than ...
It's no secret that git is terrible at handling binary files out of the box. This can often be addressed with git plugins...
Read more >
What is a binary file and how does it work? - TechTarget
A binary file is a file whose content is in a binary format consisting of a series of sequential bytes, each of which...
Read more >
Why you should not push binary files to git? And what to do if ...
Don't worry, I'll tell you how to solve this problem? Delete files and all of its history in git; Force push to git....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found