Python ServiceNow-如何使用SOAP下载报告
我需要从Python ServiceNow-如何使用SOAP下载报告,python,soap,servicenow,Python,Soap,Servicenow,我需要从serviceNow自动下载报告 我已经能够使用python和selenium和win32com通过以下方法实现自动化。 https://test.service-now.com/sys_report_template.do?CSV&jvar_report_id=92a....7aa 使用selenium访问serviceNow,并修改firefox默认下载选项,将文件转储到windows计算机上的文件夹中 但是,由于所有这些都可以移植到linux服务器,因此我们希望将其移植到SOAP或
serviceNow
自动下载报告
我已经能够使用python
和selenium
和win32com
通过以下方法实现自动化。https://test.service-now.com/sys_report_template.do?CSV&jvar_report_id=92a....7aa
使用selenium
访问serviceNow
,并修改firefox
默认下载选项,将文件转储到windows
计算机上的文件夹中
但是,由于所有这些都可以移植到linux
服务器,因此我们希望将其移植到SOAP
或CURL
我遇到了serviceNow
用于python
的库
我试过了,如果我使用ServiceNow.py中的following设置登录名、密码和实例名,下面的代码就可以工作了
class Change(Base):
__table__ = 'change_request.do'
并在客户端脚本中执行,如上所列
但是,当我将URL替换为sys\u report\u template.do
时,出现了错误
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\SOAPpy\Parser.py", line 1080, in _parseSOAP
parser.parse(inpsrc)
File "C:\Python27\Lib\xml\sax\expatreader.py", line 107, in parse
xmlreader.IncrementalParser.parse(self, source)
File "C:\Python27\Lib\xml\sax\xmlreader.py", line 125, in parse
self.close()
File "C:\Python27\Lib\xml\sax\expatreader.py", line 220, in close
self.feed("", isFinal = 1)
File "C:\Python27\Lib\xml\sax\expatreader.py", line 214, in feed
self._err_handler.fatalError(exc)
File "C:\Python27\Lib\xml\sax\handler.py", line 38, in fatalError
raise exception
SAXParseException: <unknown>:1:0: no element found
所以,我的问题是,我们可以做些什么来实现这一目标?
我在网上寻找资源和帮助,但没有找到
非常感谢您的帮助。经过大量研究,我能够使用以下方法从servicenow
获取csv
格式的报告。我想我会在这里发布,以防其他人遇到类似的问题
import requests
import json
# Set the request parameters
url= 'https://myinstance.service-now.com/sys_report_template.do?CSV&jvar_report_id=929xxxxxxxxxxxxxxxxxxxx0c755'
user = 'my_username'
pwd = 'my_password'
# Set proper headers
headers = {"Accept":"application/json"}
# Do the HTTP request
response = requests.get(url, auth=(user, pwd), headers=headers )
response.raise_for_status()
print response.text
response.text
现在有csv
格式的报告。
接下来我需要弄清楚,如何解析响应
对象以正确格式提取csv
数据。
完成后,我将在这里发布。但现在这回答了我的问题 我试过这个,它的效果和预期的一样。
`导入请求
导入json
url=“”
用户='我的用户名'
pwd='我的密码'
response=requests.get(url,auth=(user,pwd),headers=headers)
文件\u name=“abc.csv”
打开(文件名为“wb”)作为输出文件:
out\u file.write(response.content)
德尔反应`
from servicenow import ServiceNow
from servicenow import Connection
from servicenow.drivers import SOAP
# For SOAP connection
conn = SOAP.Auth(username='abc', password='def', instance='test')
rpt = ServiceNow.Base(conn)
rpt.__table__ = "sys_report_template.do?CSV"
#jvar_report_id replaced with .... to protect confidentiality
report = rpt.fetch_one({'jvar_report_id': '92a6760a......aas'})
for eachline in report:
print eachline
import requests
import json
# Set the request parameters
url= 'https://myinstance.service-now.com/sys_report_template.do?CSV&jvar_report_id=929xxxxxxxxxxxxxxxxxxxx0c755'
user = 'my_username'
pwd = 'my_password'
# Set proper headers
headers = {"Accept":"application/json"}
# Do the HTTP request
response = requests.get(url, auth=(user, pwd), headers=headers )
response.raise_for_status()
print response.text