---
title: "Trac系统的双重认证"
author: "huangro"
date: "2009-10-20T09:27:53Z"
tags: ["Python"]
slug: "trac"
draft: false
lastmod: "2009-10-20T09:27:53Z"
id: 494877
url: "https://huangro.iteye.com/blog/494877"
---

首先，需要导入urllib2及cookielib。
然后，关键部分代码：

```python

cj = cookielib.LWPCookieJar()
ah = urllib2.HTTPDigestAuthHandler()
ah.add_password(realm, login_addr, username, password)
ch = urllib2.HTTPCookieProcessor(cj)
opener2 = urllib2.build_opener(ah, ch)
urllib2.install_opener(opener2)

```


其他的就是常规的登录操作了。