From bec613b94b56736f13336c729d0861d1c6448d0b Mon Sep 17 00:00:00 2001 From: lanbaba Date: Thu, 3 Dec 2015 14:38:16 +0800 Subject: [PATCH] Fix UnicodeDecodeError when using Chinese Characters in format() function.Check returned code in getPrepayId() function --- wzhifuSDK.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/wzhifuSDK.py b/wzhifuSDK.py index 19f2707..f7b0de2 100644 --- a/wzhifuSDK.py +++ b/wzhifuSDK.py @@ -48,6 +48,10 @@ except ImportError: pycurl = None +import sys +reload(sys) +sys.setdefaultencoding('utf-8') + class WxPayConf_pub(object): """配置账号信息""" @@ -367,8 +371,11 @@ def getPrepayId(self): """获取prepay_id""" self.postXml() self.result = self.xmlToArray(self.response) - prepay_id = self.result["prepay_id"] - return prepay_id + if "return_code" in self.result and self.result["return_code"].upper() == "SUCCESS": + prepay_id = self.result["prepay_id"] + return prepay_id + else: + return None class OrderQuery_pub(Wxpay_client_pub): @@ -607,7 +614,5 @@ def test(): c2 = HttpClient() assert id(c) == id(c2) - - if __name__ == "__main__": test()