使用python将war部署到tomcat

我正在尝试使用
python(2.4.2)将战争部署到Apache Tomcat服务器(Build 6.0.24),作为构建过程的一部分.

我正在使用以下代码

import urllib2
import base64

war_file_contents = open('war_file.war','rb').read()

username='some_user'
password='some_pwd'

base64string =  base64.encodestring('%s:%s' % (username, password))[:-1]
authheader =  "Basic %s" % base64string

opener = urllib2.build_opener(urllib2.HTTPHandler)
request = urllib2.Request('http://localhost:8080/manager/deploy?path=war_file', data=war_file_contents)

request.add_header('Content-Type', 'application/octet-stream')
request.add_header("Authorization", authheader)

request.get_method = lambda: 'PUT'
url = opener.open(request)

url.code为200,url.msg为“OK”.但是,Web存档不会出现在管理器列表应用程序页面上.

谢谢.

最佳答案 好吧,想通了.

urllib2.Request行需要在路径前面有一个斜杠,所以: –

request = urllib2.Request('http://localhost:8080/manager/deploy?path=/war_file', data=war_file_contents)

一切正常.

点赞