{"action":"opened","issue":{"url":"https://api.github.com/repos/celery/kombu/issues/874","repository_url":"https://api.github.com/repos/celery/kombu","labels_url":"https://api.github.com/repos/celery/kombu/issues/874/labels{/name}","comments_url":"https://api.github.com/repos/celery/kombu/issues/874/comments","events_url":"https://api.github.com/repos/celery/kombu/issues/874/events","html_url":"https://github.com/celery/kombu/issues/874","id":325512799,"number":874,"title":"Different safe_str behavior between 4.1.0 and 4.2.0 with Python 2.7","user":{"login":"selimt","id":15021762,"avatar_url":"https://avatars2.githubusercontent.com/u/15021762?v=4","gravatar_id":"","url":"https://api.github.com/users/selimt","html_url":"https://github.com/selimt","followers_url":"https://api.github.com/users/selimt/followers","following_url":"https://api.github.com/users/selimt/following{/other_user}","gists_url":"https://api.github.com/users/selimt/gists{/gist_id}","starred_url":"https://api.github.com/users/selimt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/selimt/subscriptions","organizations_url":"https://api.github.com/users/selimt/orgs","repos_url":"https://api.github.com/users/selimt/repos","events_url":"https://api.github.com/users/selimt/events{/privacy}","received_events_url":"https://api.github.com/users/selimt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-05-23T00:59:29Z","updated_at":"2018-05-23T00:59:29Z","closed_at":null,"author_association":"NONE","body":"Hi, we use the kombu.utils.encoding.safe_str method to handle the encoding of unicode strings in Python 2.7. Between kombu 4.1.0 and 4.2.0 we are getting different results:\r\n\r\n```\r\n> setenv LANG en_US.UTF-8\r\n> pip install kombu==4.1.0 --user\r\n> python\r\n>>> f = u'Ame\\u0301lie'\r\n>>> print f\r\nAmélie\r\n>>> from kombu.utils.encoding import safe_str\r\n>>> safe_str(f)\r\n'Ame\\xcc\\x81lie'\r\n```\r\nvs\r\n```\r\n> pip install kombu==4.2.0 --user\r\n> python\r\n>>> f = u'Ame\\u0301lie'\r\n>>> print f\r\nAmélie\r\n>>> from kombu.utils.encoding import safe_str\r\n>>> safe_str(f)\r\nu'Ame\\u0301lie'\r\n```\r\n\r\nLooks like this change is due to this commit:\r\n\r\nhttps://github.com/celery/kombu/commit/39e733c14347f982e38e27c9f9edd7c400798e69\r\n\r\nThe problem we are having is that if we try to call safe_str on a unicode string and try to write it to a file, we get a UnicodeEncode error:\r\n\r\n```\r\n>>> import tempfile\r\n>>> f = u'Ame\\u0301lie\\n'\r\n>>> with tempfile.NamedTemporaryFile(dir='/tmp', delete=False) as manifest:\r\n...   manifest.write(safe_str(f))\r\n... \r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 2, in <module>\r\nUnicodeEncodeError: 'ascii' codec can't encode character u'\\u0301' in position 3: ordinal not in range(128)\r\n```\r\n\r\nThanks in advance\r\n-Selim\r\n"}}
{"actor":{"display_login":"selimt"}}