質問

その答えを 前の質問 このNexusを実施 カスタム認証のヘルパー というNxBASIC".

どんな実施のハンドラブ?


更新:

実施のハンドラに当たりアレックスの提案に見えるのが、失敗した引き出そうとしている今の制度及び領域からのauthreq.返された値authreqは:

str: NxBASIC realm="Sonatype Nexus Repository Manager API""

AbstractBasicAuthHandler.rx.検索(authreq)が返す単一のタプル:

tuple: ('NxBASIC', '"', 'Sonatype Nexus Repository Manager API')

なので、領域=mo.グループ()が失敗します。から限定正規表現の知識のようになる標準正規表現からAbstractBasicAuthHandlerを一致させる必要があ制度領域がっていないようです。

の正規表現は:

rx = re.compile('(?:.*,)*[ \t]*([^ \t]+)[ \t]+'
                'realm=(["\'])(.*?)\\2', re.I)

更新2:検査からのAbstractBasicAuthHandler、デフォルトの処理は:

scheme, quote, realm = mo.groups()

変化することです。うかを設定する必要はありパスワードに対する正します。コアレックス!

役に立ちましたか?

解決

場合、以上述べたように、名前および説明の唯一の違いはこの"NxBasic"は、古き良き"基本"、それが基本的にコピー-ペースト編集部からコードurllib2.py (残念ながらいくのスキーム名として簡単にoverridable自体は、以下のとおりです urllib2.py'sオンライン源):

import urllib2

class HTTPNxBasicAuthHandler(urllib2.HTTPBasicAuthHandler):

    def http_error_auth_reqed(self, authreq, host, req, headers):
        # host may be an authority (without userinfo) or a URL with an
        # authority
        # XXX could be multiple headers
        authreq = headers.get(authreq, None)
        if authreq:
            mo = AbstractBasicAuthHandler.rx.search(authreq)
            if mo:
                scheme, realm = mo.groups()
                if scheme.lower() == 'nxbasic':
                    return self.retry_http_basic_auth(host, req, realm)

    def retry_http_basic_auth(self, host, req, realm):
        user, pw = self.passwd.find_user_password(realm, host)
        if pw is not None:
            raw = "%s:%s" % (user, pw)
            auth = 'NxBasic %s' % base64.b64encode(raw).strip()
            if req.headers.get(self.auth_header, None) == auth:
                return None
            req.add_header(self.auth_header, auth)
            return self.parent.open(req)
        else:
            return None

ご覧のとおり修を実施みずほ銀行では、私を変更二つの文字列から"基礎"と"NxBasic"(小文字の現金及び現金同等物)からかurrlib2.py (基礎authハンドラのスーパークラスのhttp基本認証のハンドラクラス)

使い方はこのメンバーがまだまだ動いていない少なくとも有するコードで追加印刷/ロギング諸表の投資を維持しながら、生産性などに対する理解を深めるという何の破れという。最高の実績があります。せんさらにはまったく泳げないんだけど---Nexus周辺には実験しました。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top