Giter VIP home page Giter VIP logo

Comments (4)

septatrix avatar septatrix commented on July 17, 2024

Thanks for the traceback. I have already found the problem (though do not yet know what the best solution is). It seems like python cannot encode the name of the node. A minimal working example should be print("o\u0308").

The sequence o%CC%88 is the url encoded value for ö(o\xcc\x88). Note that this is different from the variant \xc3\xb6 which stands also for ö. These are two different unicode representations of the same character.

I made a small script to demonstrate this:

Script and output
import unicodedata
from urllib.parse import unquote

a = unquote("%C3%B6")
b = unquote("o%CC%88")

print(f"Variant A: {a}")
print(f"Variant B: {b}")

for form in ["NFC", "NFD"]:
    print()
    print(f"Form: {form}")
    print(f"A: {unicodedata.normalize(form, a).encode()}")
    print(f"B: {unicodedata.normalize(form, b).encode()}")

print()
print(f"Variant A (utf8): {a.encode('utf8')}")
print(f"Variant B (utf8): {b.encode('utf8')}")

print()
print(f"Variant A (latin1): {a.encode('cp1252')}")
print(f"Variant B (latin1): {b.encode('cp1252')}")
Variant A: ö
Variant B: ö

Form: NFC
A: b'\xc3\xb6'
B: b'\xc3\xb6'

Form: NFD
A: b'o\xcc\x88'
B: b'o\xcc\x88'

Variant A (utf8): b'\xc3\xb6'
Variant B (utf8): b'o\xcc\x88'

Variant A (latin1): b'\xf6'
Traceback (most recent call last):
  File "/tmp/septatrix-playground-2021-10-25T18-14-34-zhP/codec.py", line 22, in <module>
    print(f"Variant B (latin1): {b.encode('cp1252')}")
  File "/usr/lib64/python3.9/encodings/cp1252.py", line 12, in encode
UnicodeEncodeError: 'charmap' codec can't encode character '\u0308' in position 1: character maps to <undefined>

However I am not sure how we should solve this. We could always normalize these to the NFC unicode form but that would also lead to different filenames and potentially redownloading them.

Sadly I currently do not have a windows machine at hand and this works under linux as this depends on the terminal encoding. Should you have access to another terminal emulator (and shell) you might try if the minimal example I gave above works in some of them e.g. the new Windows Terminal or an embedded terminal in some IDE (in combination with powershell.exe though it should depend on the terminal).

from syncmymoodle.

septatrix avatar septatrix commented on July 17, 2024

Okay after I found out about PEP 528 it seems that this should no longer be the case if you are running a modern version of python. Could you please check and tell me which version you have installed?

PS: Based on your traceback it seems like you are using 3.9 - is that correct? Did you maybe redirect the output to a file?

from syncmymoodle.

NiklasVousten avatar NiklasVousten commented on July 17, 2024

Correct. Im using python 3.9 inside a virtual environment. But i think I have started it inside the git bash terminal. I'll try with a different terminal on windows. Maybe it is a git bash problem

Edit: It works in powershell, the files got downloaded. So the problem is the git bash on windows

from syncmymoodle.

septatrix avatar septatrix commented on July 17, 2024

I am inclined to close this as a wontfix. While we could check the encoding of the terminal and encode every string with the backslashreplace fallback this is not really a clean solution. Given that this seems to only happen in the git-bash terminal (and for a colleague of mine not event there) and the workaround is rather simple this is not worth the effort. Additionally I have a branch laying around on which the remaining prints are replaced with logging statements which are written to stderr by default which should always use the backslashreplace.

from syncmymoodle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.