From 5dfc74c85100a2a910de232b838c1f7bfa60a45d Mon Sep 17 00:00:00 2001 From: Chinmay Pai Date: Mon, 30 Sep 2019 16:59:58 +0530 Subject: [PATCH] fix(amazon-mws): python3 compatibility changes (#19210) Signed-off-by: Chinmay D. Pai --- .../doctype/amazon_mws_settings/amazon_methods.py | 12 +++++------- .../doctype/amazon_mws_settings/amazon_mws_api.py | 6 +++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_methods.py b/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_methods.py index b9be9c0b9c..2f39dc596b 100644 --- a/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_methods.py +++ b/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_methods.py @@ -4,10 +4,7 @@ from __future__ import unicode_literals import frappe, time, dateutil, math, csv -try: - from StringIO import StringIO -except ImportError: - from io import StringIO +from six import StringIO import erpnext.erpnext_integrations.doctype.amazon_mws_settings.amazon_mws_api as mws from frappe import _ @@ -26,7 +23,7 @@ def get_products_details(): listings_response = reports.get_report(report_id=report_id) #Get ASIN Codes - string_io = StringIO(listings_response.original) + string_io = StringIO(frappe.safe_decode(listings_response.original)) csv_rows = list(csv.reader(string_io, delimiter=str('\t'))) asin_list = list(set([row[1] for row in csv_rows[1:]])) #break into chunks of 10 @@ -294,7 +291,8 @@ def create_sales_order(order_json,after_date): so.submit() except Exception as e: - frappe.log_error(message=e, title="Create Sales Order") + import traceback + frappe.log_error(message=traceback.format_exc(), title="Create Sales Order") def create_customer(order_json): order_customer_name = "" @@ -451,7 +449,7 @@ def get_charges_and_fees(market_place_order_id): shipment_item_list = return_as_list(shipment_event.ShipmentEvent.ShipmentItemList.ShipmentItem) for shipment_item in shipment_item_list: - charges, fees = [] + charges, fees = [], [] if 'ItemChargeList' in shipment_item.keys(): charges = return_as_list(shipment_item.ItemChargeList.ChargeComponent) diff --git a/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_mws_api.py b/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_mws_api.py index 68c2b9c324..9925dc4a08 100755 --- a/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_mws_api.py +++ b/erpnext/erpnext_integrations/doctype/amazon_mws_settings/amazon_mws_api.py @@ -65,7 +65,8 @@ def calc_md5(string): """ md = hashlib.md5() md.update(string) - return base64.encodestring(md.digest()).strip('\n') + return base64.encodestring(md.digest()).strip('\n') if six.PY2 \ + else base64.encodebytes(md.digest()).decode().strip() def remove_empty(d): """ @@ -87,8 +88,7 @@ class DictWrapper(object): self.original = xml self._rootkey = rootkey self._mydict = xml_utils.xml2dict().fromstring(remove_namespace(xml)) - self._response_dict = self._mydict.get(self._mydict.keys()[0], - self._mydict) + self._response_dict = self._mydict.get(list(self._mydict)[0], self._mydict) @property def parsed(self):