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 with pythin3: 'ascii' codec can't decode byte 0xc3 #34

Closed
yurivict opened this issue Sep 23, 2018 · 14 comments
Closed

Fails with pythin3: 'ascii' codec can't decode byte 0xc3 #34

yurivict opened this issue Sep 23, 2018 · 14 comments

Comments

@yurivict
Copy link

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "setup.py", line 28, in <module>
    exec(open('ipopt/version.py').read())
  File "/usr/local/lib/python3.6/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 199: ordinal not in range(128)
@moorepants
Copy link
Collaborator

What version of cyipopt is this from?

@yurivict
Copy link
Author

0.1.8

@yurivict
Copy link
Author

The offending file: ipopt/version.py

@moorepants
Copy link
Collaborator

I need more information that you are providing. Can you try to open the file and read the contents and report the error here? The file does have a unicode character in it so I'm not sure why ascii decoding is being used. I can't reproduce this with Python 3.6 on ubuntu, the file opens fine. What OS are you using?

@yurivict
Copy link
Author

I had to apply this patch:

+--- ipopt/version.py.orig	2018-09-23 19:06:45 UTC
++++ ipopt/version.py
+@@ -4,9 +4,9 @@
+ cyipopt: Python wrapper for the Ipopt optimization package, written in Cython.
+ 
+ Copyright (C) 2012-2015 Amit Aides
+-Copyright (C) 2015-2018 Matthias Kümmerer
++Copyright (C) 2015-2018 Matthias Kummerer
+ 
+-Author: Matthias Kümmerer <matthias.kuemmerer@bethgelab.org>
++Author: Matthias Kummerer <matthias.kuemmerer@bethgelab.org>
+ (original Author: Amit Aides <amitibo@tx.technion.ac.il>)
+ URL: https://github.com/matthias-k/cyipopt
+ License: EPL 1.0

@moorepants
Copy link
Collaborator

Here is what I get:

(py36) moorepants@garuda:cyipopt-git-fork((v0.1.8))$ python
Python 3.6.1 |Continuum Analytics, Inc.| (default, May 11 2017, 13:09:58) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> with open('ipopt/version.py', 'r') as f: text =f.read()
... 
>>> text
'#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n"""\ncyipopt: Python wrapper for the Ipopt optimization package, written in Cython.\n\nCopyright (C) 2012-2015 Amit Aides\nCopyright (C) 2015-2018 Matthias Kümmerer\n\nAuthor: Matthias Kümmerer <matthias.kuemmerer@bethgelab.org>\n(original Author: Amit Aides <amitibo@tx.technion.ac.il>)\nURL: https://github.com/matthias-k/cyipopt\nLicense: EPL 1.0\n"""\n\n__version__ = \'0.1.8\'\n'
>>> print(text)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
cyipopt: Python wrapper for the Ipopt optimization package, written in Cython.

Copyright (C) 2012-2015 Amit Aides
Copyright (C) 2015-2018 Matthias Kümmerer

Author: Matthias Kümmerer <matthias.kuemmerer@bethgelab.org>
(original Author: Amit Aides <amitibo@tx.technion.ac.il>)
URL: https://github.com/matthias-k/cyipopt
License: EPL 1.0
"""

__version__ = '0.1.8'

@moorepants
Copy link
Collaborator

I had to apply this patch:

I'd prefer to keep Matthais name spelled correctly in the files and find our why this fails on your machine. Python 3.6 should be able to read unicode just fine.

@yurivict
Copy link
Author

yurivict commented Sep 24, 2018

It's not on my machine. This is in the FreeBSD port. This happened before, but I never understood why this happens.

@moorepants
Copy link
Collaborator

Are you packaging it for FreeBSD or something? If so, then just apply the patch downstream. Otherwise, I am not sure if enough details are provided. I am not familiar with FreeBSD and don't have an easy way to reproduce this. Maybe the Python on FreeBSD has an issue?

@yurivict
Copy link
Author

I am investigating, and asked FreeBSD this question: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=231650

@moorepants
Copy link
Collaborator

@yurivict Can you test #35 ? Maybe that simple fix works.

@yurivict
Copy link
Author

As it turned out, the open call defaults to ASCII.
You need to specify the encoding: open(filename, encoding="utf-8").

@yurivict
Copy link
Author

@moorepants This patch fixes the problem.

moorepants added a commit that referenced this issue Sep 24, 2018
Open version.py with utf-8 encoding, fixes #34.
@moorepants
Copy link
Collaborator

There is now a 0.1.9 on pypi with this fix. Thanks for the help.

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