英文:
How to properly create a POST request with correct XML to get information back from the ISAPI - Hikvision in Python?
问题
以下是您要翻译的内容:
import requests
from requests.auth import HTTPDigestAuth
headers = {'Content-Type': 'application/xml'}
output = requests.post("http://{}/{}".format(targetIP, apiPath),
auth=HTTPDigestAuth(login, password), data=payload, headers=headers, timeout=30)
这段代码在不需要payload的所有POST请求中运行良好。我得到了漂亮的XML响应,一切都很好。
但是,一旦我尝试运行此API调用:
ISAPI/ContentMgmt/logSearch
带有以下payload:
"""<?xml version="1.0" encoding="UTF-8"?>
<CMSearchDescription>
<searchID>CA32CBsadasdasda1A83</searchID>
<metaId>log.std-cgi.com/Operation/devicePowerOn</metaId>
<timeSpanList>
<timeSpan>
<startTime>2023-02-09T00:00:00Z</startTime>
<endTime>2023-03-09T23:59:59Z</endTime>
</timeSpan>
</timeSpanList>
<maxResults>100</maxResults>
</CMSearchDescription>"""
我开始收到以下响应:
<?xml version="1.0" encoding="UTF-8" ?>
<ResponseStatus version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<requestURL>/ISAPI/ContentMgmt/logSearch</requestURL>
<statusCode>5</statusCode>
<statusString>Invalid XML Format</statusString>
<subStatusCode>badXmlFormat</subStatusCode>
</ResponseStatus>
我承认我对此有些困惑。我直接从浏览器获得了XML负载,XML与使用ISAPI调用的海康威视NVR主页使用的XML完全相同,当然,搜索ID已更改。
我真的不知道这有什么问题,如果有人有任何想法,将不胜感激。
只是提醒一下,我已经尝试过在Google中搜索我的这个特殊问题,并找到了这个问题:https://stackoverflow.com/questions/45995307/hikvision-log-search-rest-api-post-method-giving-invalid-xml-format
不幸的是,这并没有提高我的机会。
英文:
I have tried doing the above with the foloowing:
import requests
from requests.auth import HTTPDigestAuth
headers = {'Content-Type': 'application/xml'}
output = requests.post("http://{}/{}".format(targetIP,apiPath),
auth=HTTPDigestAuth(login, password), data=payload, headers=headers, timeout=30)
This code, works for all post requests where payload is not needed. I am getting beautiful xml responses and everything is dandy.
However, as soon as I tried running this api call:
ISAPI/ContentMgmt/logSearch
with this as payload:
"""<?xml version="1.0" encoding="UTF-8"?>
<CMSearchDescription>
<searchID>CA32CBsadasdasda1A83</searchID>
<metaId>log.std-cgi.com/Operation/devicePowerOn</metaId>
<timeSpanList>
<timeSpan>
<startTime>2023-02-09T00:00:00Z</startTime>
<endTime>2023-03-09T23:59:59Z</endTime>
</timeSpan>
</timeSpanList>
<maxResults>100</maxResults>
</CMSearchDescription>"""
I started getting this in response:
<?xml version="1.0" encoding="UTF-8" ?>
<ResponseStatus version="1.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
<requestURL>/ISAPI/ContentMgmt/logSearch</requestURL>
<statusCode>5</statusCode>
<statusString>Invalid XML Format</statusString>
<subStatusCode>badXmlFormat</subStatusCode>
</ResponseStatus>
I admit I am a bit stuck on this. I got the XML payload directly from the browser and the xml is exactly as the one used by the Hikvision's NVR homepage that uses ISAPI calls, with changed searchID of course.
I really dont know what is wrong with this and if anyone has any ideas, they will be greatly appreciated.
Just and FYI, I have already tried googling this particular problem of mine and came accross this question: https://stackoverflow.com/questions/45995307/hikvision-log-search-rest-api-post-method-giving-invalid-xml-format
Unfortunatelly, this hasnt improved my odds.
答案1
得分: 0
您的负载似乎不正确。请将其从<searchID>CA32CBsadasdasda1A83</searchID>更改为以以下格式格式化的任何类型的字符串:<searchID>C92DC285-8F30-0001-40C6-F0EFA8FB18B5</searchID>。如此处所示https://stackoverflow.com/a/62505522。
英文:
Your payload does not seem to be correct. Please change it from <searchID>CA32CBsadasdasda1A83</searchID> to any type of string but formatted in this manner: <searchID>C92DC285-8F30-0001-40C6-F0EFA8FB18B5</searchID>. As shown here https://stackoverflow.com/a/62505522
答案2
得分: 0
这实际上需要是一个POST请求,而我当时正在使用GET请求。没有删除问题,因为也许有其他人正在做同样的事情,可能会发现这个答案有帮助。
英文:
Actually, I didnt realise, but this needs to be a POST request, while I was utilising GET request. Not deleting the question, as perhaps someone else is doing the same and might find this answer helpful.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论