You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from git import Repo, Commit
gr = Repo('/tmp/gentoo')
c = gr.commit('13e644bb36a0b1f3ef0c2091ab648978d18f369d')
print(c.authored_date)
This returns:
Traceback (most recent call last):
File "/Users/dspadini/Documents/pydriller/tmp.py", line 341, in <module>
print(c.authored_date)
File "/Users/dspadini/Documents/pydriller/venv/lib/python3.7/site-packages/gitdb/util.py", line 253, in __getattr__
self._set_cache_(attr)
File "/Users/dspadini/Documents/pydriller/venv/lib/python3.7/site-packages/git/objects/commit.py", line 144, in _set_cache_
self._deserialize(BytesIO(stream.read()))
File "/Users/dspadini/Documents/pydriller/venv/lib/python3.7/site-packages/git/objects/commit.py", line 502, in _deserialize
self.gpgsig = sig.rstrip(b"\n").decode('ascii')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 75: ordinal not in range(128)
The problem is in this line. The line to be decoded is the following:
Thanks a lot for posting! In GitPython, all handling of string encodings is somewhat botched, as it was written in a time when things were silently assumed to be ascii only.
I would be happy about a PR, it looks like changing this to .decode('UTF-8', 'ignore') would do the job in most cases, while never being able to fail, and without breaking backwards compatibility.
If there was a rewrite, one would have to stop assuming any encoding, and work with bytes instead, to leave the decoding to the consumer.
Activity
Byron commentedon Sep 3, 2019
Thanks a lot for posting! In GitPython, all handling of string encodings is somewhat botched, as it was written in a time when things were silently assumed to be ascii only.
I would be happy about a PR, it looks like changing this to
.decode('UTF-8', 'ignore')would do the job in most cases, while never being able to fail, and without breaking backwards compatibility.If there was a rewrite, one would have to stop assuming any encoding, and work with bytes instead, to leave the decoding to the consumer.