我一直在寻找是否有一种简单的方法来编写对本地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)
答案 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()