0

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 ?

6
  • 2
    Please can you add details about the error message you see and how you are using this script with Automator. Mar 10 '15 at 10:47
  • Yes, this is a common issue. UTF-8 and Python quite often don't play nice. Mar 10 '15 at 11:12
  • Sorry @GrahamMiln it's in french : grab.by/FrIG, but you can copy/paste this code in automator i think.
    – lefakir
    Mar 10 '15 at 11:57
  • @JohnKeates do you mean with automator or in a more general way ?
    – lefakir
    Mar 10 '15 at 11:58
  • With Python in a more general way. Unicode support requires some additional work to play nice with python. I learned this the hard way while working with SaltStack. Mar 10 '15 at 11:59
1

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 :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .