Skip to content

http requests fail for some domains (tested with libraries: urllib, requests) #495

@theCalcaholic

Description

@theCalcaholic

Description

With iron python, http requests to certain domains fail with System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. while they succeed with CPython (tested version: Python 2.7.15).
Since I have no idea what it is about these domains which breaks the request, I'll provide an example url below.
I've also tried using the requests library instead of urllib, with the same result.

Steps to Reproduce

  1. import urllib
  2. urllib.urlretrieve("https://build.torchapi.net/job/Torch/job/Torch/job/master/61/artifact/bin/torch-server.zip")

Expected behavior:

The file 'torch-server.zip' should be downloaded into the current directory

Actual behavior:

The following error occurs:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\IronPython 2.7\Lib\urllib.py", line 98, in urlretrieve
  File "C:\Program Files\IronPython 2.7\Lib\urllib.py", line 245, in retrieve
  File "C:\Program Files\IronPython 2.7\Lib\urllib.py", line 213, in open
  File "C:\Program Files\IronPython 2.7\Lib\urllib.py", line 443, in open_https
  File "C:\Program Files\IronPython 2.7\Lib\httplib.py", line 1038, in endheaders
  File "C:\Program Files\IronPython 2.7\Lib\httplib.py", line 882, in _send_output
  File "C:\Program Files\IronPython 2.7\Lib\httplib.py", line 844, in send
  File "C:\Program Files\IronPython 2.7\Lib\httplib.py", line 1262, in connect
  File "C:\Program Files\IronPython 2.7\Lib\ssl.py", line 359, in wrap_socket
  File "C:\Program Files\IronPython 2.7\Lib\ssl.py", line 611, in __init__
  File "C:\Program Files\IronPython 2.7\Lib\ssl.py", line 840, in do_handshake
IOError: System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at Microsoft.Scripting.Runtime.LightExceptions.ThrowException(LightException lightEx)
   at Microsoft.Scripting.Runtime.LightExceptions.CheckAndThrow(Object value)
   at Microsoft.Scripting.Interpreter.FuncCallInstruction`2.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.HandleException(InterpretedFrame frame, Exception exception)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at IronPython.Compiler.PythonCallTargets.OriginalCallTarget3(PythonFunction function, Object arg0, Object arg1, Object arg2)
   at IronPython.Runtime.Method.MethodBinding`2.SelfTarget(CallSite site, CodeContext context, Object target, T0 arg0, T1 arg1)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute4[T0,T1,T2,T3,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at Microsoft.Scripting.Interpreter.FuncCallInstruction`7.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run5[T0,T1,T2,T3,T4,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
   at IronPython.Compiler.Ast.CallExpression.Invoke2Instruction.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run6[T0,T1,T2,T3,T4,T5,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
   at IronPython.Compiler.PythonCallTargets.OriginalCallTarget5(PythonFunction function, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute7[T0,T1,T2,T3,T4,T5,T6,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
   at IronPython.Runtime.Method.MethodBinding`4.SelfTarget(CallSite site, CodeContext context, Object target, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute6[T0,T1,T2,T3,T4,T5,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
   at IronPython.Compiler.Ast.CallExpression.Invoke4Instruction.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run6[T0,T1,T2,T3,T4,T5,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
   at IronPython.Compiler.PythonCallTargets.OriginalCallTarget5(PythonFunction function, Object arg0, Object arg1, Object arg2, Object arg3, Object arg4)
   at IronPython.Runtime.FunctionCaller`1.Default4Call1(CallSite site, CodeContext context, Object func, T0 arg0)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at Microsoft.Scripting.Interpreter.FuncCallInstruction`6.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at IronPython.Compiler.Ast.CallExpression.Invoke1Instruction.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)
   at IronPython.Compiler.PythonScriptCode.RunWorker(CodeContext ctx)
   at IronPython.Hosting.PythonCommandLine.<>c__DisplayClass27_0.<RunOneInteraction>b__0()

The exact same script runs fine with CPython.

Versions

IronPython 2.7.8 2.7.8.0 on .NET 4.0.30319.42000

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions