将Python NTLM XML响应写入本地XML文件

时间:2016-05-17 20:20:24

标签: python xml ntlm

我一直在寻找是否有一种简单的方法来编写对本地XML文件的NTLM响应。我该怎么做呢?

import requests
import ntlm3 as ntlm
from requests_ntlm import HttpNtlmAuth

SITE = "website.com/_api/..."
USERNAME = 'user'
PASSWORD = 'pass'

response = requests.get(SITE, auth=HttpNtlmAuth(USERNAME,PASSWORD))

print(response.status_code)
print(response.text)

1 个答案:

答案 0 :(得分:0)

假设NTLM response.text是一个结构良好的XML,只需将文本值转储到file:

xmlfile = open('Output.xml', 'wb')
xmlfile.write(response_text)
xmlfile.close()

要将输出打印到文件,请考虑lxml模块:

import lxml.etree as ET

...

dom = ET.fromstring(response.text)
tree_out = ET.tostring(dom, pretty_print=True)

xmlfile = open('Output.xml', 'wb')
xmlfile.write(tree_out)
xmlfile.close()