在測試過程中爲我的Django 1.9項目中,我得到一個錯誤:功能assertIn導致的UnicodeDecodeError
的Python這個代碼發誓:
def test_students_list(self):
# make request to the server to get homepage page
response = self.client.get(self.url)
# do we have student name on a page?
self.assertIn('Vitaliy', response.content)
如何設置爲相同的編碼函數assertIn中的參數? 我試過這樣:
self.assertIn(u"Vitaliy", response.content.decode('utf8'))
的結果是一樣的...
附:我的Python 2.7.6在Ubuntu 14.04
我有同樣的,這是因爲響應包含unicode但HTTPResponse.content正在給你ascii。我無法弄清楚如何改變這一點。運行代碼的系統在默認語言環境中具有UTF-8,Django的默認設置爲響應爲unicode。我很難過。 – wjdp