如何使用PySVN捕获登录失败? [英] How to catch login failures with PySVN?

查看:321
本文介绍了如何使用PySVN捕获登录失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一般是Python和PySVN的新手,我正尝试使用pysvn导出我的SVN存储库.这是我的代码:

I'm new to Python and PySVN in general, and I'm trying to export my SVN repository using pysvn. Here's my code:

#set up svn login data  
def svn_credentials (realm, username, may_save):  
  return True, svn_login_name, svn_login_password, False

#establish connection  
svn_client = pysvn.Client ()  
svn_client.callback_get_login = svn_credentials

#export data  
svn_client.export('server-path-goes-here', 'client-path-goes-here', force=True)

这可以正常工作,但是如果密码错误或用户名未知,则只保留此代码.我相信它会在SVN端显示一个用户登录提示,但是我对如何检查callback_get_login发生什么感到迷惑.任何帮助将不胜感激.

Which works fine, but if the password is wrong or the user name is unknown, this code just sits. I believe it's being presented with a user login prompt on the SVN side, but I'm at a loss as to how to check what's happening with callback_get_login. Any help would be greatly appreciated.

推荐答案

如果凭据错误,则pysvn将调用回调,如果凭据仍然错误,则将再次调用该回调,并且将继续执行该操作直到凭据正确.

If the credentials are wrong pysvn will call the callback, if the credentials are still wrong it will call it again, and again, and it will just keep doing that until the credentials are correct.

对于自动脚本,最好不要设置回调,而是通过在pysvn.Client实例上调用set_default_username和set_default_password来设置默认用户名和密码.

For an automated script you are probably better off not setting the callback and instead setting the default username and password by calling set_default_username and set_default_password on the pysvn.Client instance.

使用该设置,不正确的凭据将导致pysvn传播异常,提示您设置了可以捕获的回调并变成有意义的错误消息.

With that setup incorrect credentials will result in pysvn propagating an exception suggesting that you set the callback which you can catch and turn into a meaningful error message.

这篇关于如何使用PySVN捕获登录失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆