Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode codec error #16

Closed
dtrudg opened this issue Jun 14, 2016 · 2 comments
Closed

Unicode codec error #16

dtrudg opened this issue Jun 14, 2016 · 2 comments

Comments

@dtrudg
Copy link
Contributor

dtrudg commented Jun 14, 2016

When using python-otrs to submit an article where the text contains unicode (\u210c in this case), the following error occurs:

python-otrs

Apologies for screenshot instead of text

Looking in objects.py around line 103, I don't really understand what's going on here.

 def to_xml(self):
        """
        @returns am etree.Element
        """
        root = etree.Element(self.XML_NAME)
        for k, v in self.attrs.items():
            e = etree.Element(k)
            if isinstance(e, str):  #  True
                v = v.encode('utf-8')
            e.text = str(v)
            root.append(e)
        return root

The # True comment here suggests that v is always being encoded as utf-8, but then str(v) is applied where an encoding error is being raised.

Not sure whether this is a bug, or there is a certain way in which python-otrs is should be passed unicode content?

Thanks,

@ewsterrenburg
Copy link
Owner

Thanks for reporting. This is most likely a bug....
Could you please check for me if it works correctly if you use the following:
e.text = unicode(v)

Erwin

@dtrudg
Copy link
Contributor Author

dtrudg commented Jun 15, 2016

Confirm that change fixes the issue - it accepts unicode strings now, and they go into OTRS as expected.

diff --git a/otrs/objects.py b/otrs/objects.py
index b75bef4..fd7fb8f 100644
--- a/otrs/objects.py
+++ b/otrs/objects.py
@@ -100,7 +100,7 @@ class OTRSObject(object):
             e = etree.Element(k)
             if isinstance(e, str):  #  True
                 v = v.encode('utf-8')
-            e.text = str(v)
+            e.text = unicode(v)
             root.append(e)
         return root

ewsterrenburg added a commit that referenced this issue Jun 15, 2016
Allow unicode entries without codec error, fix #16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants