Skip to content
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

Fails when LC_CTYPE is not explicitly UTF-8 #6

Open
infinity0 opened this issue Dec 7, 2016 · 3 comments
Open

Fails when LC_CTYPE is not explicitly UTF-8 #6

infinity0 opened this issue Dec 7, 2016 · 3 comments

Comments

@infinity0
Copy link

$ LC_CTYPE="C.UTF-8" python2.7 -m unittest discover
......
----------------------------------------------------------------------
Ran 6 tests in 0.020s

OK

$ LC_CTYPE="POSIX" python2.7 -m unittest discover
.E....
======================================================================
ERROR: test_aleksandra_slapik_44 (test.test_sagenb_writer.ReadSageNB)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/infinity0/var/lib/sage/sagenb-export/test/test_sagenb_writer.py", line 39, in test_aleksandra_slapik_44
    ipynb.write(self.tmp_filename(u'WDI projekt - R\xf3\u017cankowski, Kie\u0142pi\u0144ski, Kozok.ipynb'))
  File "/home/infinity0/var/lib/sage/sagenb-export/sagenb_export/ipynb_writer.py", line 58, in write
    write(ipynb, filename)
  File "/usr/lib/python2.7/dist-packages/nbformat/__init__.py", line 163, in write
    with io.open(fp, 'w', encoding='utf-8') as f:
UnicodeEncodeError: 'ascii' codec can't encode characters in position 41-42: ordinal not in range(128)

----------------------------------------------------------------------
Ran 6 tests in 0.020s

FAILED (errors=1)
1

This is because you pass a unicode string type as a filename. Python will implicitly try to encode this using LC_CTYPE, which doesn't support that particular value. You can fix this in several ways, I'm not sure which way you prefer:

  1. Say that IpynbWriter.write can only accept byte filenames, and do the encode('utf-8') in the test. This is probably the simplest.
  2. Say that IpynbWriter.write can accept unicode string filenames too, and do encode('utf-8') in there, if it's a string type.
  3. Add a filename_encoding param to IpynbWriter.write.
@infinity0
Copy link
Author

On further investigation it looks like this is more a problem with nbformat.write - even if you pass a byte path here, that function will not accept it - it only accepts string filenames or file objects. I'll go file a bug there too instead.

@infinity0
Copy link
Author

(Note that there is still an issue in sagenb-export; but your solution will depend on how nbformat fix things on their end.)

@slel
Copy link
Collaborator

slel commented Oct 7, 2019

AFter nbformat issue jupyter/nbformat#76
was closed by pull request jupyter/nbformat#83
what remains to be done here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants