{"action":"created","issue":{"url":"https://api.github.com/repos/IronLanguages/main/issues/1108","repository_url":"https://api.github.com/repos/IronLanguages/main","labels_url":"https://api.github.com/repos/IronLanguages/main/issues/1108/labels{/name}","comments_url":"https://api.github.com/repos/IronLanguages/main/issues/1108/comments","events_url":"https://api.github.com/repos/IronLanguages/main/issues/1108/events","html_url":"https://github.com/IronLanguages/main/issues/1108","id":51462080,"number":1108,"title":"Using str() on non-ASCII string throws Exception: Unable to translate bytes from specified code page to Unicode","user":{"login":"ironpythonbot","id":2897688,"avatar_url":"https://avatars.githubusercontent.com/u/2897688?v=3","gravatar_id":"","url":"https://api.github.com/users/ironpythonbot","html_url":"https://github.com/ironpythonbot","followers_url":"https://api.github.com/users/ironpythonbot/followers","following_url":"https://api.github.com/users/ironpythonbot/following{/other_user}","gists_url":"https://api.github.com/users/ironpythonbot/gists{/gist_id}","starred_url":"https://api.github.com/users/ironpythonbot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ironpythonbot/subscriptions","organizations_url":"https://api.github.com/users/ironpythonbot/orgs","repos_url":"https://api.github.com/users/ironpythonbot/repos","events_url":"https://api.github.com/users/ironpythonbot/events{/privacy}","received_events_url":"https://api.github.com/users/ironpythonbot/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2014-12-09T18:14:31Z","updated_at":"2016-08-16T07:14:12Z","closed_at":null,"body":"I am hosting IronPython (IronPython.dll 2.7.4.1000; Microsoft.Scripting.dll\n1.1.0.21) inside a .NET 4.0 application.  \n  \nThe IronPyhton.Runtime throws a System.Text.DecoderFallbackException whenever\nI use the built-in Python str() function on a non-ASCII string.  \n  \nSo basically, when I execute the following python code:  \n\n    \n    \n    s = str(\"ä\")\n\nI get a ** System.Text.DecoderFallbackException ** \"Unable to translate bytes\n[E4] at index 0 from specified code page to Unicode.\"  \n  \nThis is problematic, since I use str() almost everywhere to convert various\ntypes (unknown at rutime) to strings.  \n  \nHere is the complete exception info:  \n\n    \n    \n    System.Text.DecoderFallbackException was unhandled by user code\n      HResult=-2147024809\n      Index=0\n      Message=Unable to translate bytes [E4] at index 0 from specified code page to Unicode.\n      Source=mscorlib\n      StackTrace:\n           at System.Text.DecoderExceptionFallbackBuffer.Throw(Byte[] bytesUnknown, Int32 index)\n           at System.Text.DecoderExceptionFallbackBuffer.Fallback(Byte[] bytesUnknown, Int32 index)\n           at IronPython.Runtime.PythonAsciiEncoding.GetCharCount(Byte[] bytes, Int32 index, Int32 count)\n           at System.Text.Encoding.GetChars(Byte[] bytes, Int32 index, Int32 count)\n           at System.Text.Encoding.GetString(Byte[] bytes, Int32 index, Int32 count)\n           at IronPython.Runtime.Operations.StringOps.DoDecode(CodeContext context, String s, String errors, String encoding, Encoding e)\n           at IronPython.Runtime.Operations.StringOps.RawDecode(CodeContext context, String s, Object encodingType, String errors)\n           at IronPython.Runtime.Operations.StringOps.decode(CodeContext context, String s, Object encoding, String errors)\n           at IronPython.Runtime.Operations.StringOps.__new__(CodeContext context, PythonType cls, Object string, String encoding, String errors)\n           at IronPython.Runtime.Operations.StringOps.CheckAsciiString(CodeContext context, String s)\n           at IronPython.Runtime.Operations.StringOps.__new__(CodeContext context, PythonType cls, String object)\n           at Microsoft.Scripting.Interpreter.FuncCallInstruction`4.Run(InterpretedFrame frame)\n           at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)\n           at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)\n           at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)\n           at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)\n           at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)\n           at Microsoft.Scripting.Interpreter.LightLambda.Run1[T0,TRet](T0 arg0)\n           at IronPython.Compiler.PythonCallTargets.OriginalCallTarget0(PythonFunction function)\n           at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)\n           at _Scripting_(Object[] )\n           at App.Test.Misc.IronPythonUmlautTest() in C:\\Dev\\App\\Test\\Misc.vb:line 79\n      InnerException: \n    \n\nHere is a unit test that reproduces the issue (sorry it's in VB.NET):  \n\n    \n    \n        <TestMethod()> _\n        Public Sub IronPythonUmlautTest()\n            Dim e = IronPython.Hosting.Python.CreateEngine()\n            Dim s As Microsoft.Scripting.Hosting.ScriptScope\n            Dim code As String\n            Dim f As Func(Of Object)\n    \n            ' TEST 1: Returning string directly works\n            s = e.CreateScope()\n            code = \"def somefunction():      \" & vbCrLf & _\n                   \"    s = \"\"ä\"\"            \" & vbCrLf & _\n                   \"    return s             \"\n    \n            e.CreateScriptSourceFromString(code).Execute(s)\n            f = s.GetVariable(Of Func(Of Object))(\"somefunction\")\n    \n            ' Ok\n            Assert.IsTrue(CStr(f()) = \"ä\")\n    \n    \n            ' TEST 2: Returning string set via .NET\n            s = e.CreateScope()\n            s.SetVariable(\"astring\", \"ä\")\n            code = \"def somefunction():      \" & vbCrLf & _\n                   \"    return astring       \"\n    \n            e.CreateScriptSourceFromString(code).Execute(s)\n            f = s.GetVariable(Of Func(Of Object))(\"somefunction\")\n    \n            ' Ok\n            Assert.IsTrue(CStr(f()) = \"ä\")\n    \n    \n            ' TEST 3: Running string through Python str() function\n            s = e.CreateScope()\n            code = \"def somefunction():      \" & vbCrLf & _\n                   \"    s = \"\"ä\"\"            \" & vbCrLf & _\n                   \"    return str(s)        \"\n    \n            e.CreateScriptSourceFromString(code).Execute(s)\n            f = s.GetVariable(Of Func(Of Object))(\"somefunction\")\n    \n            ' The following line throws a System.Text.DecoderFallbackException: \n            ' Unable to translate bytes [E4] at index 0 from specified code page to Unicode.\n            Assert.IsTrue(CStr(f()) = \"ä\")\n    \n    \n            ' TEST 4: Running string from .NET through Python str() function\n            s = e.CreateScope()\n            s.SetVariable(\"astring\", \"ä\")\n            code = \"def somefunction():      \" & vbCrLf & _\n                   \"    return str(astring)  \"\n    \n            e.CreateScriptSourceFromString(code).Execute(s)\n            f = s.GetVariable(Of Func(Of Object))(\"somefunction\")\n    \n            ' The following line throws a System.Text.DecoderFallbackException: \n            ' Unable to translate bytes [E4] at index 0 from specified code page to Unicode.\n            Assert.IsTrue(CStr(f()) = \"ä\")\n        End Sub\n    \n    \n\nWork Item Details\n--------------------\n**Original CodePlex Issue:**\t[Issue 35199](http://ironpython.codeplex.com/workitem/35199)\n**Status:**\tProposed\n**Reason Closed:**\tUnassigned\n**Assigned to:**\tUnassigned\n**Reported on:**\tMay 7 at 10:55 AM\n**Reported by:**\tacl2\n**Updated on:**\tMay 10 at 12:36 AM\n**Updated by:**\tpaweljasinski\n"},"comment":{"url":"https://api.github.com/repos/IronLanguages/main/issues/comments/240021812","html_url":"https://github.com/IronLanguages/main/issues/1108#issuecomment-240021812","issue_url":"https://api.github.com/repos/IronLanguages/main/issues/1108","id":240021812,"user":{"login":"simplicbe","id":14359329,"avatar_url":"https://avatars.githubusercontent.com/u/14359329?v=3","gravatar_id":"","url":"https://api.github.com/users/simplicbe","html_url":"https://github.com/simplicbe","followers_url":"https://api.github.com/users/simplicbe/followers","following_url":"https://api.github.com/users/simplicbe/following{/other_user}","gists_url":"https://api.github.com/users/simplicbe/gists{/gist_id}","starred_url":"https://api.github.com/users/simplicbe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simplicbe/subscriptions","organizations_url":"https://api.github.com/users/simplicbe/orgs","repos_url":"https://api.github.com/users/simplicbe/repos","events_url":"https://api.github.com/users/simplicbe/events{/privacy}","received_events_url":"https://api.github.com/users/simplicbe/received_events","type":"User","site_admin":false},"created_at":"2016-08-16T07:14:11Z","updated_at":"2016-08-16T07:14:11Z","body":"@kunom thank you for creating a pull request! But why waiting for CI?"}}
{"actor":{"display_login":"simplicbe"}}