.net - IronPython urllib2 Basic Auth Exceptions? (Shopify)
I'm creating a private Shopify app, that uses basic authentication. The program is to be written in IronPython, however, I'm having trouble getting urllib2 working.
I've tried the solution from here: Python urllib2 Basic Auth Problem (https://stackoverflow.com/questions/2407126/python-urllib2-basic-auth-problem)
and it works as expected with plain python, but when run with IronPython, I get this error:
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.Socket.Receive(Byte buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.Read(Byte buffer, Int32 offset, Int32 size) --- End of inner exception stack trace --- at Microsoft.Scripting.Runtime.LightExceptions.CheckAndThrow(Object value) at DLRCachedCode.do_open$5398(Closure , PythonFunction $function, Object self, Object http_class, Object req) at IronPython.Runtime.FunctionCaller`3.Call3(CallSite site, CodeContext context, Object func, T0 arg0, T1 arg1, T2 ar...
I tried an all .NET solution in IronPython (not using urllib2) and it works, using this method: http://www.ironpython.info/index.php?title=Fetching_a_Page_with_Basic_Authentication (http://www.ironpython.info/index.php?title=Fetching_a_Page_with_Basic_Authentication)
Is there some magic going on behind the scenes (python -> .NET) causing this not to work?
Current version of IronPython defaults to SSL v2. Assuming your server is accepting TLS1 you need the following before you use urllib2
import ssl import functools old_init = ssl.SSLSocket.__init__ @functools.wraps(old_init) def init_with_tls1(self, *args, **kwargs): kwargs['ssl_version'] = ssl.PROTOCOL_TLSv1 old_init(self, *args, **kwargs) ssl.SSLSocket.__init__ = init_with_tls1
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.