-1

I am getting this error "UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 17: ordinal not in range(128)" when I try to merge this image "La Pocatière.png".

    Python 2.7.11
    bg_img = Image(filename='C:/Pocatière.png')
    bg_img.resize(1200,628)
    bg_img.composite('C:/test.png', left=0, top=0)

when I do print I can see the right unicode:

bg_img
u'La Pocati\xe8re.png'
>>> print bg_img
La Pocatière.png

Not sure how I can bypass this issue?


Answer: After doing lots research and in discussion with my colleague we were able to solve this issue by setting : text_encoding = 'utf-8' For some reason wand wasn't able to set it automatically

mrzoogle
  • 111
  • 3
  • 14
  • Is this python v2 or v3? as in v2 you might be better of with calling `Image(filename=u'C:/Pocatière.png')` you can also notice this in the working sample where it states `u'La Pocati\xe8re.png'` – Dilettant Jun 06 '16 at 16:32
  • The reference contributed by @l'L'l is definitely useful ;-) but I suspect, that the string literal as function parameter is here the problem. Hopefully the OP will tell ... – Dilettant Jun 06 '16 at 16:36
  • @Dilettant since there are *unicode* strings, and `print bg_img` in the code, I'd be surprised if this was python 3. Or am I missing something obvious? – Andras Deak -- Слава Україні Jun 17 '16 at 23:28
  • @AndrasDeak It is python 2.7 – mrzoogle Jun 20 '16 at 16:37

1 Answers1

2

Is this python v2 or v3?

In case this is Python version 2 (which I think it is), then you might be better of with calling

Image(filename=u'C:/Pocatière.png') 

you can also notice this in the working sample where it states

u'La Pocati\xe8re.png'
Dilettant
  • 3,267
  • 3
  • 29
  • 29
  • thanks for advice. I am getting the file path as a variable. How would I do it in this case. `bg_url = background_img_path+"/"+background_img.decode('utf-8')` `bg_img = Image(filename=bg_url)` `bg_img.resize(1200,628)` `bg_img.composite(fg_url, left=0, top=0)` – mrzoogle Jun 07 '16 at 10:00
  • If I remove ".decode('utf-8') from the code I get below error: BlobError: unable to open image `C:/La Pocati�re.png': No such file or directory @ error/blob.c/OpenBlob/2702 – mrzoogle Jun 07 '16 at 10:02
  • Is this python v2 or v3? Would be good to know. In your sample (above comment) for python v2, you would have `bg_url` be a byte string (info lost) due to not using os.path method, but injecting `"/"`instead of u`"/"` right? Then the filename parameter again would receive a bytestring instead of the (i think) expected unicode string. So given, that `background_img_path` and `background_img` are also unicode strings, why not use: `bg_url = background_img_path+u"/"+background_img` or the like? – Dilettant Jun 07 '16 at 10:45
  • this is python v2.7, I've tried `bg_url = background_img_path+u"/"+background_img` but still getting same error message. "BlobError" :( Do you think `bg_url = background_img_path+"/"+background_img.decode('utf-8')` problem lies in this code? – mrzoogle Jun 07 '16 at 13:06
  • also the background_img_path is being send via form `background_img_path = request.form.get("imgpath")` I have fixed this "/" in jinja template so now I have this `bg_url = background_img_path+background_img` Tried this too with no success `os.path.join(background_img_path, background_img)` – mrzoogle Jun 07 '16 at 13:19