Automator and python script utf-8 output

automatorpythonutf-8

I wrote a python shell script and it fails in automator workflow :

# -*- coding: utf-8 -*-

import urllib, json, os, datetime
import locale
locale.setlocale(locale.LC_ALL, 'fr_FR')

url = "http://feeds.delicious.com/v2/json/lefakir/ws?count=8"

urllib.urlopen(url)

deliciousFeed = urllib.urlopen(url)

posts = json.load(deliciousFeed)

for post in posts:
    print " * {0} : [{1}]({2})".format(post["n"], post["d"], post["u"])

The problem occurs on post["n"] and post["d"] which have utf-8 symbols.

Is it a common issue ?

Best Answer

I found myself :

print " * {0} : [{1}]({2})".format(post["n"].encode( "utf-8" ), post["d"].encode( "utf-8" ), post["u"].encode( "utf-8" ))

It was an unicode/utf-8 problem :)