Handling authentication and proxies with httplib2

I am trying to test interactions with a Nexus server, which requires authentication for the operations that I intend to use, but I also need to process the internal proxy.

Based on my (limited) understanding, I can add multiple handlers to the opener. However, I still get a 401 response. I checked the username and password. I'm not sure if cookies are needed for this, and if so, how will they be included. Any suggestions?

baseUrl = 'server:8070/nexus-webapp-1.3.3/service/local'

params = {"[key]":"[value]"}

data = urllib.urlencode(params)

# create a password manager
password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()

# Add the username and password as supplied
password_mgr.add_password(None, baseUrl, username, password)

handler = urllib2.HTTPBasicAuthHandler(password_mgr)
proxy_support = urllib2.ProxyHandler({})

# create "opener" (OpenerDirector instance)
opener = urllib2.build_opener(proxy_support, handler)
urllib2.install_opener(opener)

txheaders =  {'User-agent' : 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'}

req = Request(protocol+url, data, txheaders)
handle = urlopen(req)

This is the resulting URLError header field:

>HTTPMessage: Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=B4BD05C9582F7B27495CBB675A339724; Path=/nexus-webapp-1.3.3
WWW-Authenticate: NxBASIC realm="Sonatype Nexus Repository Manager API"
Content-Type: text/html;charset=utf-8
Content-Length: 954
Date: Fri, 03 Jul 2009 17:38:42 GMT
Connection: close

Update Nexus seems to be implementing a custom version of Restlete AuthenticationHelper . Thanks to Alex, I knew what to look for.

+2
1

401, ? , auth, , , - , !

: ( "", ).

, "Basic", - ( Nexus...?) "NxBASIC" - ( Nexus), , ( NxBASIC - , , , , ​​ ).

, , NxBASIC, , SO . , , , ...! - (

+3

Source: https://habr.com/ru/post/1711836/


All Articles