0

我正在尝试在 python 中运行查询并遇到错误。

我是 SQL 领域的新手,我们的一位 DBA 编写了这个 SQL 命令,它在他们的机器上运行。但是,当我将其转换为 Python 时,我遇到了问题。

import requests
from orionsdk import SwisClient

npm_server = 'SERVER'
username = 'USERNAME'
password = 'PASSWORD'

verify = False
if not verify:
    from requests.packages.urllib3.exceptions import InsecureRequestWarning
    requests.packages.urllib3.disable_warnings(InsecureRequestWarning)


swis = SwisClient(npm_server, username, password)

print("Query Test:")

query = """
SELECT NodesData.Caption as NodeName, IP_Address,
Interfaces.InterfaceName,
Interfaces.Status, Interfaces.InterfaceLastChange
 FROM Interfaces
 INNER JOIN NodesData ON Interfaces.NodeID = NodesData.NodeID
 INNER JOIN NodesCustomProperties (NOLOCK) ON NodesData.NodeID = NodesCustomProperties.NodeID
LEFT OUTER JOIN WebCommunityStrings ON WebCommunityStrings.CommunityString = NodesData.Community
 WHERE Interfaces.Status = 2 AND Interfaces.Severity > 0 AND InterfaceName = 'Tunnel201' ORDER BY NodesData.Caption, Interfaces.InterfaceIndex DESC
"""
results = swis.query(query)

for row in results['results']:
    #print("{NodeID:<5}: {DisplayName}".format(**row))
    print("{NodeID:<5}: {DisplayName}".format(**row))

输出:

C:\Users\jefhill\AppData\Local\Programs\Python\Python37-32\python.exe "C:/Users/jefhill/Desktop/Python Stuff/Projects/solarWinds/swExport.py"
Query Test:
Traceback (most recent call last):
  File "C:/Users/jefhill/Desktop/Python Stuff/Projects/solarWinds/swExport.py", line 30, in <module>
    results = swis.query(query)
  File "C:\Users\jefhill\AppData\Local\Programs\Python\Python37-32\lib\site-packages\orionsdk\swisclient.py", line 26, in query
    {'query': query, 'parameters': params}).json()
  File "C:\Users\jefhill\AppData\Local\Programs\Python\Python37-32\lib\site-packages\orionsdk\swisclient.py", line 63, in _req
    resp.raise_for_status()
  File "C:\Users\jefhill\AppData\Local\Programs\Python\Python37-32\lib\site-packages\requests\models.py", line 940, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 400 Client Error: mismatched input ')' expecting 'EQ' in Join clause for url: https://SERVER:PORT/SolarWinds/InformationService/v3/Json/Query

Process finished with exit code 1

注意:删除了一些更私密的信息(IE、服务器名称、密码等)

4

0 回答 0