2016-05-11 10 views
2

serviceNowからレポートのダウンロードを自動化する必要があります。ServiceNow - SOAPを使用してレポートをダウンロードする方法

私はpythonseleniumwin32comを使って以下の方法で自動化することができました。
https://test.service-now.com/sys_report_template.do?CSV&jvar_report_id=92a....7aa

そしてserviceNowにアクセスするだけでなく、windowsマシン上のフォルダにファイルをダンプするfirefoxデフォルトのダウンロードオプションを変更するseleniumを使用。

ただし、これはすべてlinuxサーバーに移植されるため、SOAPまたはCURLに移植します。

pythonhereのライブラリserviceNowが見つかりました。使用してサイトに記載されているように私はServiceNow.py

class Change(Base): 
    __table__ = 'change_request.do' 

から次とsiteに記載されているとして、クライアント側のスクリプト内で次のログイン、パスワードおよびインスタンス名を設定した場合

は、私はそれを試してみたし、次のコードは動作しています。私は sys_report_template.doとURLを交換した場合、エラー

ここ
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 

だからreleventコード

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 

あるしかし、私は、私の質問は、作るために何を行うことができますされて取得しています

# Fetch changes updated on the last 5 minutes 
changes = chg.last_updated(minutes=5) 
#print changes client side script. 

for eachline in changes: 
    print eachline 

この作品? ウェブでリソースを探して助けを求めたが、見つからなかった。

何か助けていただければ幸いです。

答えて

1

多くの研究の末、csv形式の報告書をservicenowから入手するために、以下の方法を使用することができました。他の誰かが同様の問題に遭遇した場合に私がここに投稿すると思った。

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形式でレポートを持っています。
responseオブジェクトを解析して、正しいフォーマットのcsvデータを抽出する方法を次に把握する必要があります。
完了したら、ここに投稿します。しかし今のところ、これは私の質問に答えるものです。

関連する問題