0
服務器錯誤: 蟒蛇2.7Python中字符編碼不一致之間環境
Traceback (most recent call last):
File "promoter.py", line 325, in process_unfollowbacks
self.add_user_to_database(user_info)
File "promoter.py", line 618, in add_user_to_database
str(u['name']),
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe7' in position 11: ordinal not in range(128)
然而,它運行在Ubuntu罰款。
服務器:
Python 2.7.3 (default, Mar 2 2014, 10:09:03)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Ubuntu的:
Python 2.7.5+ (default, Feb 27 2014, 19:37:08)
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
我通過對來自Twitter的JSON數組(Twython模塊)產生的字典操作收到此錯誤,但是我不認爲故障在那裏。
一個小檢查表明這是用外語發生。
問題: 如何處理環境之間的這種不一致?
.encode( 'UTF-8')是我做的第一件事,然而,即使拋出的錯誤。 – Orangeman555
這會產生什麼?打印'%r'%u ['名字'] – user590028