How to authenticate with the Milestone server 2017-R2 using Python?

Hello,

+ Is it possible to connect Milestone server 2017-R2 using Python?

+ I followed the local “Html/index.html” instruction in to login using SOAP Requests with Python: “Home > Protocol Integration > Protocols > ImageServer > ImageServer - Authenticate”. This is my code snipper:

def soap_over_http():

_"""_

_Payload note:_

    _+ If you are targeting XProtect Enterprise, you will need to replace {SERVICE\_PATH} with ServerCommandService_

    _+ Replace {guid} in the <instanceId> element's content by a new random GUID, which is different every time your application runs._

    _+ The first time you make this request, the <currentToken> element should be omitted._

_"""_

url = "[http://107.125.6.161/ServerCommandService/ServerCommandService.asmx](http://107.125.6.161/ServerCommandService/ServerCommandService.asmx)"

payload = """

<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:xsi=[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance) xmlns:xsd="[http://www.w3.org/2001/XMLSchema](http://www.w3.org/2001/XMLSchema)" xmlns:soap="[http://schemas.xmlsoap.org/soap/envelope/](http://schemas.xmlsoap.org/soap/envelope/)">

<soap:Body>

<Login xmlns="[http://videoos.net/2/XProtectCSServerCommand](http://videoos.net/2/XProtectCSServerCommand)">

<instanceId>c2du20we-3a1d-4e63-bf28-0daf1b59bcb7</instanceId>

</Login>

</soap:Body>

</soap:Envelope>

"""

headers = {'Content-Type': 'text/xml; charset=utf-8'}

try:

    resp = requests.request(

        "POST", url, headers=headers, data=payload, timeout=5)

    print("PASS", resp.content)

except Exception as e:

    print("ERROR", e)

+ Response:

\\r\\n\\r\\n \\r\\n The resource cannot be found.\\r\\n
<meta name="viewport" content="width=device-width" />\\r\\n

\\r\\n\\r\\n \\r\\n\\r\\n
    <H1>Server Error in \\'/\\' Application.

        <hr width=100% size=1 color=silver>

    </H1>\\r\\n\\r\\n <h2> <i>The resource cannot be found.</i> </h2>

</span>\\r\\n\\r\\n <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">\\r\\n\\r\\n <b> Description:

    </b>HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its

    name changed, or is temporarily unavailable. &nbsp;Please review the following URL and make sure that it is

    spelled correctly.\\r\\n <br><br>\\r\\n\\r\\n

    <b> Requested URL: </b>/ServerCommandService/ServerCommandService.asmx<br><br>\\r\\n\\r\\n </body>\\r\\n
\\r\\n'

I would love to hear any solution.

If you have an example like the address “https://doc.developer.milestonesys.com/mipvmsapi/api/events-rest/v1/#section/Quickstart/Python”, that would be great.

Please help.

As far as I can tell you did find the right documentation. One idea is that you build and run the TCP Video Viewer or the LoginDotNetSoap sample, doing so you can do a network trace to detect how the samples send the SOAP. Or perhaps reading the code of the sample might be a good hint.

Unfortunately I have never seen a Python sample code for this, and the version is very old and out of support. I hope my tip will be helpful and you get it to work.

My resources:

  • Server MGMT: 107.125.5.161
  • Server REC: 107.125.5.162
  • Opened firewall to port: 80/443/7563
  • Milestone server 2017-R2

I share the results after testing both methods.

  • LoginDotNetSoap:

Enter username or blank for default credentials: username

Enter password: ******

Enter domain (Enter “basic” for a basic authentication user): basic

Enter IP address and port for the XProtect VMS [localhost:443] : http://107.125.6.161:443

Does the server use encryption? [y/n] n

Token returned: TOKEN#adsa1234-1a2s-3b2s-82ef-24293985f621#mb1local01.smartv3t.com//ServerConnector#

Token is valid for: 14400 seconds

Enter IP address for an XProtect Recording Server (or blank for same as Mgt Server): http://107.125.6.162

Unhandled Exception: System.Net.Sockets.SocketException: No such host is known

at System.Net.Dns.GetAddrInfo(String name)

at System.Net.Dns.InternalGetHostByName(String hostName, Boolean includeIPv6)

at System.Net.Dns.GetHostEntry(String hostNameOrAddress)

at LoginDotNetSoap_CS.Program.Main(String[] args) in [C:\Users\](file:C:/Users/)***\mipsdk-samples-protocol\LoginDotNetSoap\Program.cs:line 140

[C:\Users\](file:C:/Users/)***\mipsdk\mipsdk-samples-protocol\LoginDotNetSoap\bin\Debug\LoginDotNetSoap.exe (process 4064) exited with code -532462766.

Have you encountered this error?

If you can provide additional scripts to fix this error, it would be great.

You do actually login! The way I read it it is the last step of communicating with the recording server that fails. When you get token you are logged in. Double-check the Recording Server address. For a E-code XProtect the address should be the same as the login. For a C-code XProtect the recording server can be another machine but then per default on port 7563.

E-code: XProtect Enterprise, Professional, Express

C-code: XProtect Corporate, Expert, Professional+, Express+

Hi,

Is there an inconsistency between the use of .5. vs .6. in:

  • Server MGMT: 107.125.5.161
  • Server REC: 107.125.5.162

and:

url = “http://107.125.6.161/ServerCommandService/ServerCommandService.asmx

Enter IP address for an XProtect Recording Server (or blank for same as Mgt Server): http://107.125.6.162

?

BTW: This video is intended to help you connect using Protocol Integration from non-.NET framework environments such as Python:

Milestone Developer Conference 2021 - Integrations from non-.NET framework environments

= https://www.youtube.com/watch?v=txKKsLz7zB8

and related

Samples for DevCon21 session on Protocol integrations from Linux: Tips and Tricks

= https://developer.milestonesys.com/s/question/0D53X00009QOrhvSAD/samples-for-devcon21-session-on-protocol-integrations-from-linux-tips-and-tricks

Thank you for your comment. That was my typing error.