Skip to content

Fetch binary file via repo.git.show #751

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

Closed
redimp opened this issue Apr 24, 2018 · 1 comment
Closed

Fetch binary file via repo.git.show #751

redimp opened this issue Apr 24, 2018 · 1 comment

Comments

@redimp
Copy link

redimp commented Apr 24, 2018

I want to fetch a binary file via repo.git.show. That works until I want to handle it as binary file.

from io import BytesIO
import git
    
# initialize repository
repo = git.Repo('.')
# use git show to get the content of example.jpg in revision 19e91a
u = repo.git.show("4cb2a02:example.jpg")

b = BytesIO(u.encode('utf-8'))

I run into

UnicodeEncodeError: 'utf-8' codec can't encode character '\udcff' in position 0: surrogates not allowed

Can I fetch the file binary in any way?

This is more a feature request than a bug. I want to apologize if this is not the correct way to handle it.

@redimp
Copy link
Author

redimp commented Apr 24, 2018

I solved it thanks to https://stackoverflow.com/a/50004051/212768

b = BytesIO(u.encode('utf-8','surrogateescape'))

@redimp redimp closed this as completed Apr 24, 2018
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