0

I'm trying to fetch some album data from Python. It works flawless locally, but there is a weird character encoding problem remotely. Does anyone have similar experience?

I have the same database backend and DB collaction locally and remotely, still the remote running of the above code fails on DB write.

My code is the following

# I'm running the follogin code:

def fetch_albums(page_id):
    graph = get_app_graph() # a facebook GraphAPI

    albums = graph.get_connections(page_id, 'albums')
    albums = graph.get_objects(map(lambda album: album['id'], albums['data']), 
        fields='id,name,description,count,type,created_time,updated_time')

    for id, album in albums.items():
        album_data = {
            u'id': int(id),
            u'name': album['name'],
        }
        print album_data['id'], album_data['name']
        models.Gallery.objects.get_or_create(id=int(id), defaults=album_data)

local fetch prints:

361515390548186 Wall Photos
438411299525261 Untitled Album
165700500129677 FlashMob
438439616189096 Jalagati
463020007064390 Jógaterem festés Szegeden!
257436427622750 Szegedi jógaterem
447917535241304 Liget-Jóga 2012.07.16.
440165949349796 Untitled Album
391850364181355 Aranykor jóga
467681026598288 Untitled Album
365378980161827 Cover Photos
459389304094127 Pesti jógaterem
175279379171789 Wall Photos
467157249983999 Jalagati Születésnap 2012-09-08
459154937450897 Jógaterem -Pest
269294046436988 Jógafesztivál (2011)
265207220179004 Sportágválasztó nap - 2011.09.24.
399868300046228 Föld napi jóga | SZTE-TIK, Szeged
206952096004517 A szigeten
456442934388764 Untitled Album
459392610760463 Untitled Album
459134537452937 Lótusz Napok
165697500129977 Profile Pictures

remote fetch prints:

361515390548186 Wall Photos
438411299525261 Untitled Album
165700500129677 FlashMob
438439616189096 Jalagati
463020007064390 J����������������������8�������������������!����������������
(and dies here on DB get_or_create)
Akasha
  • 2,162
  • 1
  • 29
  • 47
  • 1
    It is unclear what remote and local means this the context of the question. Howver I recommend you to check the sys default encoding setting in Python http://stackoverflow.com/questions/2276200/changing-default-encoding-of-python – Mikko Ohtamaa Sep 09 '12 at 21:15
  • It wouldn't be too surprising if your computer and the host you're fetching from have different encodings. How are you "locally fetching" the data, what is the encoding of the locally fetched data, and what is the encoding of the remotely fetched data? – BrenBarn Sep 09 '12 at 21:19
  • @MikkoOhtamaa unfortunately the setdefaultencoding method did not solve my problem as both local and remote console was already set to ascii – Akasha Sep 09 '12 at 21:57
  • @MikkoOhtamaa remote and local: I'm writing a django gallery app that would fetch facebook albums to show to the users integrated into a website. Local means my development maching, while remote is a staging server running at webfaction. – Akasha Sep 09 '12 at 21:59
  • @BrenBarn could you help me to figure out the encoding of the fetched data, please? I don't know how to find it out. – Akasha Sep 09 '12 at 22:00
  • Wherever you're fetching the data from should have some documentation telling you what encoding it's in (e.g., in the API docs). There are heuristics to guess the encoding from the data, but the whole point is you should know what the encoding will be before you even get the data. – BrenBarn Sep 09 '12 at 22:04

1 Answers1

0

found the problem

the problem was that on my host provider my default python is ver 2.6.x, while on my dev machine it's 2.7.x

the problem was present only under 2.6

Akasha
  • 2,162
  • 1
  • 29
  • 47