1 Reply Latest reply: Nov 15, 2013 3:13 AM by René van Wijk RSS

    urllib2 in python compared to WLST

    Nick.Beenham

      Hi all,

       

      A bit of a puzzler here. I have a piece of python that I wrote to download binaries as part of a deployment script. this works fine in python 2.7.5 but in WLST 12.1.1 I am getting a 401 unauthorized error. How does wlst handle auth differently from python. The repourl is the base url which is then built upon depending on the package from the array.

       

      # Add credentials and create a handler

        password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()

        password_mgr.add_password(None, repourl, username, password)

        handler = urllib2.HTTPBasicAuthHandler(password_mgr)

       

       

        opener = urllib2.build_opener(handler)

        urllib2.install_opener(opener)

       

       

        for app in apps:

          try:

            grouppath = re.sub('\.','/', app['groupId'])

            filename = app['artifactId'] + '-' + app['version'] + '.' + app['packaging']

            url = repourl + '/' + 'libs-release' + '/' + grouppath + '/' + app['artifactId'] + '/' + app['version'] + '/' + filename

            print('Downloading %s' % (url))

            response = urllib2.urlopen(url)

            local_file = open(filename, 'wb')

            local_file.write(response.read())

            local_file.close()

          except Exception, err:

            continue

       

       

      The error I get is

       

      Problem invoking WLST - Traceback (innermost last):

        File "/home/nick/development/projects/bulkdeployer/bulkdeployer.py", line 76, in ?

        File "/home/nick/development/projects/bulkdeployer/bulkdeployer.py", line 62, in retrieveArtifacts

        File "/opt/platform/fmw_home/wlserver_12.1/common/wlst/modules/jython-modules.jar/Lib/urllib2$py.class", line 138, in urlopen

        File "/opt/platform/fmw_home/wlserver_12.1/common/wlst/modules/jython-modules.jar/Lib/urllib2$py.class", line 327, in open

        File "/opt/platform/fmw_home/wlserver_12.1/common/wlst/modules/jython-modules.jar/Lib/urllib2$py.class", line 307, in _call_chain

        File "/opt/platform/fmw_home/wlserver_12.1/common/wlst/modules/jython-modules.jar/Lib/urllib2$py.class", line 824, in http_open

        File "/opt/platform/fmw_home/wlserver_12.1/common/wlst/modules/jython-modules.jar/Lib/urllib2$py.class", line 818, in do_open

        File "/opt/platform/fmw_home/wlserver_12.1/common/wlst/modules/jython-modules.jar/Lib/urllib2$py.class", line 354, in error

        File "/opt/platform/fmw_home/wlserver_12.1/common/wlst/modules/jython-modules.jar/Lib/urllib2$py.class", line 307, in _call_chain

        File "/opt/platform/fmw_home/wlserver_12.1/common/wlst/modules/jython-modules.jar/Lib/urllib2$py.class", line 406, in http_error_default

      HTTPError: HTTP Error 401: Unauthorized