0

我正在尝试从 Python 获取一些专辑数据。它在本地运行完美,但远程存在奇怪的字符编码问题。有没有人有类似的经历?

我在本地和远程拥有相同的数据库后端和数据库收集,但上述代码的远程运行在数据库写入时仍然失败。

我的代码如下

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

本地获取打印:

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

远程获取打印:

361515390548186 Wall Photos
438411299525261 Untitled Album
165700500129677 FlashMob
438439616189096 Jalagati
463020007064390 J����������������������8�������������������!����������������
(and dies here on DB get_or_create)
4

1 回答 1

0

发现问题

问题是在我的主机提供商上我的默认 python 是 2.6.x,而在我的开发机器上它是 2.7.x

问题仅在 2.6 下出现

于 2012-09-09T22:44:02.633 回答