From bd17dfe019a5cc2691e9974d37a3b6980e2021d5 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Wed, 5 Apr 2017 16:51:58 +0200 Subject: [PATCH] [FIX] payment_paypal: pdt parsing - accept error as response In case of error, paypal return some lines where error message and not a string with 'key=value'. This commit fix traceback: ValueError: dictionary update sequence element #0 has length 1; 2 is required --- addons/payment_paypal/controllers/main.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/addons/payment_paypal/controllers/main.py b/addons/payment_paypal/controllers/main.py index bdf35742bec..2fefb1417ef 100644 --- a/addons/payment_paypal/controllers/main.py +++ b/addons/payment_paypal/controllers/main.py @@ -32,16 +32,22 @@ class PaypalController(http.Controller): :param response str: text response, structured in the following way: STATUS\nkey1=value1\nkey2=value2...\n + or STATUS\nError message...\n :rtype tuple(str, dict) :return: tuple containing the STATUS str and the key/value pairs parsed as a dict """ lines = filter(None, response.split('\n')) status = lines.pop(0) - pdt_post = dict(line.split('=', 1) for line in lines) - # html unescape - for post in pdt_post: - pdt_post[post] = urllib.unquote_plus(pdt_post[post]).decode('utf8') + + pdt_post = {} + for line in lines: + split = line.split('=', 1) + if len(split) == 2: + pdt_post[split[0]] = urllib.unquote_plus(split[1]).decode('utf8') + else: + _logger.warning('Paypal: error processing pdt response: %s', line) + return status, pdt_post def paypal_validate_data(self, **post):