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

world.cfg has UTF-8 Encoded Characters causing compile errors #11

Open
gpratt3151 opened this issue Aug 22, 2016 · 4 comments
Open

world.cfg has UTF-8 Encoded Characters causing compile errors #11

gpratt3151 opened this issue Aug 22, 2016 · 4 comments

Comments

@gpratt3151
Copy link

First of all, thank you for the project!

It looks like the file was opened in an editor that converted '...' and 'uf' to UTF-8 (like MS Word does with auto correct).

Here's the diff. I also attached a fixed version of world.cfg.

world.cfg.txt

gpratt@core ~/owslave$ diff world.cfg world.cfg.fixed
151c151
<       - 0…7: Analog input pin to read

---
>       - 0...7: Analog input pin to read
417c417
<         R-C network (10 µF @ 1 MOhm)

---
>         R-C network (10 uF @ 1 MOhm)
486c486
<         R-C network (10 µF @ 1 MOhm)

---
>         R-C network (10 uF @ 1 MOhm)

Here is the error:
Traceback (most recent call last):
File "./cfg", line 498, in
main(*sys.argv[1:])
File "./cfg", line 67, in main
s = Cfg(cfg_name)
File "/home/gpratt/owslave/Cfg.py", line 64, in init
self.data = yaml.load(fd)
File "/usr/lib/python3/dist-packages/yaml/init.py", line 70, in load
loader = Loader(stream)
File "/usr/lib/python3/dist-packages/yaml/loader.py", line 34, in init
Reader.init(self, stream)
File "/usr/lib/python3/dist-packages/yaml/reader.py", line 85, in init
self.determine_encoding()
File "/usr/lib/python3/dist-packages/yaml/reader.py", line 124, in determine_encoding
self.update_raw()
File "/usr/lib/python3/dist-packages/yaml/reader.py", line 178, in update_raw
data = self.stream.read(size)
File "/usr/lib/python3.4/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 5525: ordinal not in range(128)

Hope this helps.

-Greg

@smurfix
Copy link
Contributor

smurfix commented Aug 22, 2016

On 22.08.2016 02:40, gpratt3151 wrote:

It looks like the file was opened in an editor that converted '...'
and 'uf' to UTF-8 (like MS Word does with auto correct).

That was me. I happen to like UTF-8. :-P

This patch should work instead:

diff --git a/Cfg.py b/Cfg.py
index 3883427..2927a3c 100644
--- a/Cfg.py
+++ b/Cfg.py
@@ -60,7 +60,7 @@ class Cfg(object):
iseq = 1

 def __init__(self, f):
  •    with open(f) as fd:
    
  •    with open(f,encoding='utf-8') as fd:
         self.data = yaml.load(fd)
     self.ipath = {}
     self.data['_idata_'] = {}
    

Alternately you could "export LC_ALL=en_US.UTF-8" in the shell. That'd
magically make your Python3 work with all UTF-8 files, not just mine.

-- Matthias Urlichs

@gpratt3151
Copy link
Author

Ok. Perhaps we should put that in the README.md or HOWTO.md file? It took me a few hours to figure it out as this appears to be a very common python3 issue and doesn't throw a very good error pointing to the file in error. And, even if it did reference the file, trying to figure out a character position can be difficult. Do you prefer pull requests?

@smurfix
Copy link
Contributor

smurfix commented Aug 24, 2016

Pull requests are good.

@gpratt3151
Copy link
Author

Ok. I'll probably have some time to work on it this weekend and I'll shoot you a pull request on the documentation if I see anything. Appreciate the quick response.

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