esdalmaijer / PyGaze

an open-source, cross-platform toolbox for minimal-effort programming of eye tracking experiments
www.pygaze.org
GNU General Public License v3.0
671 stars 211 forks source link

PyGaze crash in OpenSesame using German characters #111

Open aldichollow opened 6 years ago

aldichollow commented 6 years ago

Hello, I am encountering an error in PyGaze on OpenSesame, when the trial has special character such as "ä,ö,ü,ß" and tries to log them as variables. The experiment crashes every first trial that includes german characters and I can imagine that it is related to the text-encoding error from eyelink.py, but wasn't able to fix it. As for a quick workaround, I just replaced those characters to normal alphabets, but I want to know how I can solve this.

Unexpected error

item-stack: experiment[run].german_loop[run].trial_sequence[run].pygaze_log[run]
exception type: UnicodeEncodeError
exception message: 'ascii' codec can't encode character u'\xf6' in position 12: ordinal not in range(128)
time: Mon Feb 26 15:19:27 2018

Traceback:
File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libqtopensesame\misc\process.py", line 150, in run
    exp.run()
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\experiment.py", line 411, in run
    self.items.execute(self.var.start)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 91, in execute
    self.run(name)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 106, in run
    self[name].run()
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\sequence.py", line 51, in run
    self.experiment.items.run(_item)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 106, in run
    self[name].run()
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\loop.py", line 337, in run
    self.experiment.items.execute(self._item)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 91, in execute
    self.run(name)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 106, in run
    self[name].run()
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\sequence.py", line 51, in run
    self.experiment.items.run(_item)
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\item_store.py", line 106, in run
    self[name].run()
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\share\opensesame_plugins\pygaze_log\pygaze_log.py", line 52, in run
    info[u'value'])
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\pygaze\_eyetracker\baseeyetracker.py", line 319, in log_var
    self.log(u"var %s %s" % (safe_decode(var), safe_decode(val)))
  File "C:\Program Files (x86)\OpenSesame\lib\site-packages\pygaze\_eyetracker\libeyelink.py", line 246, in log
    pylink.getEYELINK().sendMessage(msg)
  File "c:\python27\Lib\site-packages\pylink\eyelink.py", line 157, in sendMessage
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 12: ordinal not in range(128)

Versions using:

esdalmaijer commented 6 years ago

Thanks for flagging this up! I'm not entirely sure, but I doubt EyeLink files allow for non-ascii characters. @smathot, you're the unicode expert, do you know this?

For now, I'd refrain from using non-ascii characters in your log file. Sorry!

smathot commented 5 years ago

Thanks for flagging this up! I'm not entirely sure, but I doubt EyeLink files allow for non-ascii characters. @smathot, you're the unicode expert, do you know this?

sendMessage() accepts unicode. The problem here is that a byte string with non-ascii characters is provided, and pylink doesn't know how to decode it. So we should document the assumed encoding, and then when a byte string is passed use the assumed encoding to decode to unicode before passing it to sendMessage().