Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] 'ascii' codec can't decode byte 0xc3 in position 27: ordinal not in range

edited June 2014 in OpenSesame

Even though I already found another entry on this problem, I think, I cannot solve it the same way in my case but putting a 'u in the logger :P

So what happened: the experiment runs fine on my laptop but not on the computers in the lab at university.
It crashes as soon as a loop containin an inline script to set the string according to the current value of a variable, a form which contains some text, a picture, some checkboxes, a button and another inline script which creates a new variable each cycle of the loop, so that I only need one logger-Item in the end and have my values in one line.

Here's the error message in the debugging window:

Unexpected error

line: 874
exception message: 
exception type: UnicodeDecodeError

Traceback:
  File "dist\libqtopensesame\misc\process.py", line 130, in run
  File "dist\libopensesame\experiment.py", line 291, in run
  File "dist\libopensesame\sequence.py", line 56, in run
  File "dist\libopensesame\loop.py", line 145, in run
  File "dist\libopensesame\sequence.py", line 56, in run
  File "C:\Program Files (x86)\OpenSesame\plugins\form_base\form_base.py", line 136, in run
  File "dist\libopensesame\widgets\form.py", line 112, in _exec
  File "dist\libopensesame\widgets\form.py", line 224, in render
  File "dist\libopensesame\widgets\image.py", line 73, in render
  File "dist\openexp\_canvas\legacy.py", line 874, in image
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 27: ordinal not in range(128)

OS on the lab computers, where it crashes, is Win 7 Enterprise 64bit
OS on my Laptop where it was created and runs propperly is Win 8.1 64bit

I'd be thankful for a solution. Meanwhile participants use my laptop.
Cheers!

Comments

  • edited 9:17AM

    Hi,

    The error message that you see results from a problem in parsing the actual error message. In other words, the actual error message is obscured by a bug in OpenSesame's exception handling system. To see what's going, you try the following code in an inline_script:

    import pygame
    pygame.image.load(exp.get_file(u'my_filename.png'))
    

    ... replace my_filename.png by the name of the problematic file in the file pool. This script should still crash, but hopefully provide a more informative error message.

    Cheers!
    Sebastiaan

  • edited 9:17AM

    Hi Sebastiaan,

    Had to change the inline script slightly to match my usage:

    import pygame
    path = "u'%s.png'" % (self.get('ID'))
    pygame.image.load(path)
    

    The Error code now produced by this new inline script is as following:

    Error while executing inline script
    
    phase: run
    item: inline_script
    line: 3
    exception message: Couldn't open u'52.png'
    exception type: error
    
    Traceback:
      File "dist\libopensesame\inline_script.py", line 154, in run
      Inline_script, line 3, in <module>
    error: Couldn't open u'52.png'
    

    An image 52.png exists in the same folder as the experiment. And adding all the pictures to the file pool did not help either.

  • edited June 2014

    The correct code would actually be:

    import pygame
    path = u'%s.png' % (self.get('ID'))
    pygame.image.load(path)
    

    The u should be before the quotation marks if you use it to denote a unicode string. Currently, your image name is defined as u'52.png' rather than 52.png

  • edited 9:17AM

    Thanks Edwin for the correction.
    And I just realized it's jpg not png, so I corrected the path accordingly. Could the jpg-format cause the problem?

    Now the error is:

    Error while executing inline script
    
    phase: run
    item: inline_script
    line: 3
    exception message: Couldn't open 52.jpg
    exception type: error
    
    Traceback:
      File "dist\libopensesame\inline_script.py", line 154, in run
      Inline_script, line 3, in <module>
    error: Couldn't open 52.jpg
    

    Still, all pictures are in the same folder as the experiment and all pictures were added to the file pool.

    But don't worry too much, it's not critical anymore. I got used to make my participants switch seats and use my laptop for this part.

  • edited June 2014

    Hi,

    It seems OpenSesame still can't find the file. One thing that comes to mind, is using the neat way of getting file paths, using the function that @sebastiaan had already mentioned:

    import pygame
    
    # get the file name, e.g. u'52.png'
    filename = u'%s.png' % (self.get('ID'))
    
    # get the full path to the file
    path = exp.get_file(filename)
    
    # load the image, using the full path
    pygame.image.load(path)
    

    This way is preferred, as some systems are not particularly fond of abbreviated paths (i.e.: not using the full path, but just the name of a file in the working directory).

    Good luck!

  • edited 9:17AM

    Even though the thread was meanwhile marked as solved, I must admit, I just didn't try it anymore on the lab's PCs and just used my laptop. Meanwhile I'm done with this study. So thank you for all the support, Edwin and Sebastiaan! =) (a short review concerning the mobile part will be given in the runtime environment threat)

Sign In or Register to comment.