From d73f107f0628f4ee4fd85447e2790ee84bc9f5ff Mon Sep 17 00:00:00 2001 From: Anton Date: Mon, 1 Feb 2021 19:36:51 +0300 Subject: [PATCH 1/2] Fixing pdu.generate() encoding --- smpplib/command.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/smpplib/command.py b/smpplib/command.py index c2ccfd0..472534d 100644 --- a/smpplib/command.py +++ b/smpplib/command.py @@ -177,11 +177,19 @@ def _generate_string(self, field): field_value = field_value[0:self.params[field].max - 1] if field_value: - value = field_value + chr(0) + if not isinstance(field_value, bytes): + value = field_value + chr(0) + else: + value = field_value + chr(0).encode() else: - value = chr(0) + if not isinstance(field_value, bytes): + value = chr(0) + else: + value = chr(0).encode() setattr(self, field, field_value) + if isinstance(value, bytes): + return value return six.b(value) def _generate_ostring(self, field): From 8a862aeb83fef4a985e1c26dd548eb4618fc8919 Mon Sep 17 00:00:00 2001 From: Anton VG Date: Tue, 2 Feb 2021 10:16:48 +0300 Subject: [PATCH 2/2] Update smpplib/command.py Co-authored-by: Konstantin --- smpplib/command.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/smpplib/command.py b/smpplib/command.py index 472534d..926764c 100644 --- a/smpplib/command.py +++ b/smpplib/command.py @@ -188,7 +188,7 @@ def _generate_string(self, field): value = chr(0).encode() setattr(self, field, field_value) - if isinstance(value, bytes): + if isinstance(value, six.binary_type): return value return six.b(value)