我正在尝试使用requests
下载SSRS报告。以下代码将下载一个空的 Excel 文件:
url = 'http://MY REPORT URL HERE/ReportServer?/REPORT NAME HERE&rs:Format=EXCELOPENXML'
s = requests.Session()
s.post(url, data={'_username': 'username, '_password': 'password'})
r = s.get(url)
output_file = r'C:\Saved Reports\File.xlsx'
downloaded_file = open(output_file, 'wb')
for chunk in r.iter_content(100000):
downloaded_file.write(chunk)
我已成功使用requests_ntlm
来完成此任务,但我想知道为什么上面的代码没有按预期工作。 Excel 文件结果是空的;我认为这是由于登录并将这些 cookie 传递给 GET
请求时出现问题所致。
最佳答案
我能够让它工作,但是对于 pdf。我找到了解决方案here
这是我的代码片段:
import requests
from requests_ntlm import HttpNtlmAuth
session = requests.Session()
session.auth = HttpNtlmAuth(domain+uid,pwd)
response = session.get(reporturl,stream=True)
print response.status_code
with open(outputlocation+mdcProp+'.pdf','wb') as pdf:
for chunk in response.iter_content(chunk_size=1024):
if chunk:
pdf.write(chunk)
session.close()
关于python - 使用 requests 在 Python 中下载 SSRS 报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55821047/