python - Dulwich 远程 repo 认证

标签 python git authentication dulwich

是否有任何关于通过 HTTPS 访问和获取远程存储库的好示例?我有一个 Git 存储库,我可以使用我的用户名和密码从命令行克隆它,但我希望能够使用 Dulwich 执行此操作,并且在创建 HTTPS 客户端时只提供我的用户名和密码。

另一个要求是使用 MemoryRepo 选项而不是写入文件系统来完成。

最佳答案

Dulwich 0.16.0 及更高版本支持 URL 中的用户名/密码。

在旧版本中,您可以通过指定自定义 HTTP 处理程序来执行此操作:

    import urllib2

    password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()

    # Add the username and password.
    password_mgr.add_password(realm, top_level_url, username, password)

    handler = urllib2.HTTPBasicAuthHandler(password_mgr)

    opener = urllib2.build_opener([handler])

    client, path = get_transport_and_path(remote_location)
    client.opener = opener
    remote_refs = client.fetch(path, target_repo)

关于python - Dulwich 远程 repo 认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31717487/

相关文章:

Git:如何维护永久并行分支

java - 使用 SAMLResponse token

php - 如何在 Laravel 5.0 中使用 Auth::attempt 无密码登录?

python - Python中列表的迭代

python - 如何去掉小数中无用的零位?

git - Xcode 5 : Pushing and pulling from new GitHub repository does not work

authentication - Firebase 身份验证导致错误代码 "auth/network-request-failed"

python - FFMPEG - 图像到视频。来自 RAM 的图像? (Python)

python - 使用 OpenCV 为 Otsu 阈值蒙版图像区域

javascript - Gulp 正在恢复我的所有更改?