彼得,
我和我的团队都经历过同样的挑战。 Samplebias,尝试提供callback_get_login 函数,但将您的callback_server_ssl_trust_prompt 设置为返回(True, trust_dict['failures'], True)。 IFF subversion 没有缓存您的服务器证书信任设置,那么您可能会发现info2()(或Peter 的list() 命令)挂起(它实际上并没有挂起,只是间歇性地需要更长的时间才能返回)。奇怪的是,当您在这些情况下 CTRL-C 解释器时,您会得到指示它挂在登录回调上,而不是 server_cert 验证。使用您的~/.subversion/auth 设置(特别是svn.simple 和svn.ssl.server 目录),您会看到不同数量的“挂起时间”。如果您需要处理真正永远不会返回的情况,请查看pysvn.Client.callback_cancel。
考虑:http://pysvn.tigris.org/docs/pysvn_prog_ref.html#pysvn_client_callback_ssl_server_trust_prompt 你需要决定你想要的行为是什么。您是否只想允许那些您已经拥有缓存信任答案的连接?或者,您是否希望始终接受服务器证书验证(警告:这可能(显然)具有负面的安全影响)。考虑以下建议:
import pysvn
URL1 = "https://exists.your.org/svn/repos/dev/trunk/current"
URL2 = "https://doesntexit.your.org/svn/repos/dev/trunk/current"
URL3 = "https://exists.your.org/svn/repos/dev/trunk/youDontHavePermissionsBranch"
ALWAYS = "ALWAYS"
NEVER = "NEVER"
DESIRED_BEHAVIOR = ALWAYS
def ssl_server_certificate_trust_prompt(trust_dict):
if DESIRED_BEHAVIOR == NEVER:
return (False, 0, False)
elif DESIRED_BEHAVIOR == ALWAYS:
return (True, trust_dict['failures'], True)
raise Exception, "Unsupported behavior"
def testURL(url):
try:
c.info2(url)
return True
except pysvn.ClientError, ce:
if ('non-existant' in ce.args[0]) or ('Host not found' in ce.args[0]):
return False
else:
raise ce
c = pysvn.Client()
c.callback_ssl_server_trust_prompt = lambda t: (False, t['failures'], True)
c.callback_get_login = lambda x, y, z: (True, "uname", "pw", False)
if not testURL(URL1): print "Test1 failed."
if testURL(URL2): print "Test2 failed."
try:
testURL(URL3)
print "Test3 failed."
except: pass
实际上,您可能不想像我对返回值那样花哨。我确实认为分开考虑服务器返回的潜在 403 和“未找到主机”情况很重要。