Improve error handle from php to python