0

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

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

Is there some magic going on behind the scenes (python -> .NET) causing this not to work?

Community
  • 1
  • 1
user173326
  • 67
  • 8
  • What version are you using? If 2.7.4 or older, please try 2.7.5b3. – Pawel Jasinski Nov 09 '14 at 00:25
  • Was using 2.7.4, but just installed 2.7.5b3 and I get the same errors. Pawel, I noticed you're a contributor to the project, if you'd like I can send you my files and complete error logs. – user173326 Nov 09 '14 at 14:51
  • I already fixed one problem with certificate parser. There can be more. Where can find your files? – Pawel Jasinski Nov 09 '14 at 15:33
  • It's a private app, so no public repository. Code is basically the same as here: http://stackoverflow.com/a/2955687/2406696 but with Shopify API and credentials. – user173326 Nov 09 '14 at 19:08
  • not sure how to switch this thing into chat mode, so I will continue here. – Pawel Jasinski Nov 09 '14 at 19:40
  • can you give me user/test credentials to your test system? The last bug I fixed had to do with quotes in server certificate. – Pawel Jasinski Nov 09 '14 at 19:48
  • Is there a way I can reach you via email, we can figure this out and just update this question afterwards. You probably don't wanna publish your email here, maybe there's a site I can go to to dig it up? – user173326 Nov 09 '14 at 23:37
  • first name (dot) last name (at) gmail (dot) com – Pawel Jasinski Nov 10 '14 at 13:24

1 Answers1

3

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
Pawel Jasinski
  • 796
  • 3
  • 10
  • Thank you. Saved my butt today. Posting to the service bus from python has been working for weeks, all of a sudden, just stopped working. – dascalos Nov 16 '14 at 02:44