Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error during Onvif.connect #32

Closed
LODYZ opened this issue Mar 9, 2023 · 5 comments
Closed

Error during Onvif.connect #32

LODYZ opened this issue Mar 9, 2023 · 5 comments

Comments

@LODYZ
Copy link

LODYZ commented Mar 9, 2023

Hi @faithoflifedev , I am trying the new version. I'm getting this error during Onvif.connect.
Let me know if you need more attempts or information to understand the problem. Thank You!

👻 22:19:22.469037 INFO     UI Loggy - Onvif - initializing ...
🐛 22:19:22.471763 DEBUG    UI Loggy - DeviceManagement - getSystemDateAndTime
🐛 22:19:22.485712 DEBUG    UI Loggy - Onvif - URI: http://192.168.0.25/onvif/device_service
🐛 22:19:22.485808 DEBUG    UI Loggy - Onvif - REQUEST:
<?xml version="1.0" encoding="UTF-8"?><s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header/><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetSystemDateAndTime xmlns="http://www.onvif.org/ver10/device/wsdl"/></s:Body></s:Envelope>
🐛 22:19:22.666638 DEBUG    UI Loggy - Onvif - RExSPONSE:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:chan="http://schemas.microsoft.com/ws/2005/02/duplex" xmlns:wsa5="http://www.w3.org/2005/08/addressing" xmlns:c14n="http://www.w3.org/2001/10/xml-exc-c14n#" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" xmlns:wsc="http://schemas.xmlsoap.org/ws/2005/02/sc" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:ns2="http://www.onvif.org/ver10/pacs" xmlns:xmime="http://tempuri.org/xmime.xsd" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:wsrfbf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" xmlns:wsrfr="http://docs.oasis-open.org/wsrf/r-2" xmlns:ns1="http://www.onvif.org/ver10/accesscontrol/wsdl" xmlns:ns3="http://www.onvif.org/ver10/actionengine/wsdl" xmlns:tad="http://www.onvif.org/ver10/analyticsdevice/wsdl" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:trc="http://www.onvif.org/ver10/recording/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:trv="http://www.onvif.org/ver10/receiver/wsdl" xmlns:tse="http://www.onvif.org/ver10/search/wsdl" xmlns:vifsvr="http://www.onvif.org/ver10/events/wsdl/PullPointSubscriptionBinding" xmlns:vifsvr10="http://www.onvif.org/ver20/analytics/wsdl/AnalyticsEngineBinding" xmlns:vifsvr2="http://www.onvif.org/ver10/events/wsdl/EventBinding" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:vifsvr3="http://www.onvif.org/ver10/events/wsdl/SubscriptionManagerBinding" xmlns:vifsvr4="http://www.onvif.org/ver10/events/wsdl/NotificationProducerBinding" xmlns:vifsvr5="http://www.onvif.org/ver10/events/wsdl/NotificationConsumerBinding" xmlns:vifsvr6="http://www.onvif.org/ver10/events/wsdl/PullPointBinding" xmlns:vifsvr7="http://www.onvif.org/ver10/events/wsdl/CreatePullPointBinding" xmlns:vifsvr8="http://www.onvif.org/ver10/events/wsdl/PausableSubscriptionManagerBinding" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:vifsvr9="http://www.onvif.org/ver20/analytics/wsdl/RuleEngineBinding" xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl" xmlns:ter="http://www.onvif.org/ver10/error" xmlns:tns1="http://www.onvif.org/ver10/topics"><SOAP-ENV:Header></SOAP-ENV:Header><SOAP-ENV:Body><tds:GetSystemDateAndTimeResponse><tds:SystemDateAndTime><tt:DateTimeType>NTP</tt:DateTimeType><tt:DaylightSavings>false</tt:DaylightSavings><tt:TimeZone><tt:TZ/></tt:TimeZone><tt:UTCDateTime><tt:Time><tt:Hour>21</tt:Hour><tt:Minute>19</tt:Minute><tt:Second>22</tt:Second></tt:Time><tt:Date><tt:Year>2023</tt:Year><tt:Month>3</tt:Month><tt:Day>9</tt:Day></tt:Date></tt:UTCDateTime><tt:LocalDateTime><tt:Time><tt:Hour>21</tt:Hour><tt:Minute>19</tt:Minute><tt:Second>22</tt:Second></tt:Time><tt:Date><tt:Year>2023</tt:Year><tt:Month>3</tt:Month><tt:Day>9</tt:Day></tt:Date></tt:LocalDateTime></tds:SystemDateAndTime></tds:GetSystemDateAndTimeResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

🐛 22:19:23.313039 DEBUG    UI Loggy - DeviceManagement - getServices
🐛 22:19:23.313696 DEBUG    UI Loggy - Onvif - URI: http://192.168.0.25/onvif/device_service
🐛 22:19:23.313723 DEBUG    UI Loggy - Onvif - REQUEST:
<?xml version="1.0" encoding="UTF-8"?><s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header/><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetServices xmlns="http://www.onvif.org/ver10/device/wsdl"><IncludeCapability>false</IncludeCapability></GetServices></s:Body></s:Envelope>
‼️ 22:19:23.467985 ERROR    UI Loggy - Onvif - ERROR:
DioError [unknown]: null
Error: HttpException: Connection closed while receiving data, uri = http://192.168.0.25/onvif/device_service
⚠️ 22:19:23.468439 WARNING  UI Loggy - Onvif - GetServices command not supported
🐛 22:19:23.468699 DEBUG    UI Loggy - DeviceManagement - getCapabilities
🐛 22:19:23.469359 DEBUG    UI Loggy - Onvif - URI: http://192.168.0.25/onvif/device_service
🐛 22:19:23.469393 DEBUG    UI Loggy - Onvif - REQUEST:
<?xml version="1.0" encoding="UTF-8"?><s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header/><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetCapabilities xmlns="http://www.onvif.org/ver10/device/wsdl"><Category>All</Category></GetCapabilities></s:Body></s:Envelope>
‼️ 22:19:23.629413 ERROR    UI Loggy - Onvif - ERROR:
DioError [unknown]: null
Error: HttpException: Connection closed while receiving data, uri = http://192.168.0.25/onvif/device_service
Unhandled exception:
Exception: DioError [unknown]: null
Error: HttpException: Connection closed while receiving data, uri = http://192.168.0.25/onvif/device_service
#0      Transport.sendRequest (package:easy_onvif/src/soap/transport.dart:48:7)
<asynchronous suspension>
#1      DeviceManagement.getCapabilities (package:easy_onvif/src/device_management.dart:81:22)
<asynchronous suspension>
#2      Onvif.initialize (package:easy_onvif/src/onvif_base.dart:149:28)
<asynchronous suspension>
#3      Onvif.connect (package:easy_onvif/src/onvif_base.dart:92:5)
<asynchronous suspension>
#4      OnvifHelperCommand.initializeOnvif (package:easy_onvif/cmd/onvif_helper_command.dart:29:14)
<asynchronous suspension>
#5      OnvifGetDeviceInformationResponseDeviceManagementCommand.run (package:easy_onvif/cmd/onvif_device_management_command.dart:225:5)
<asynchronous suspension>
#6      CommandRunner.runCommand (package:args/command_runner.dart:212:13)
<asynchronous suspension>
@faithoflifedev
Copy link
Owner

Hi @LODYZ , I really don't know what's happening with that connection issue. I've read here - https://dart.dev/tools/pub/troubleshoot - that anti-virus software can cause the issue.

I also found that one of the code changes that you referred to here - LODYZ@aed87fa - did not make it into the new build. I've published v2.1.0-dev.9 that includes the change.

@LODYZ
Copy link
Author

LODYZ commented Mar 13, 2023

Hi @faithoflifedev, i've inspected the situation and probably found the problem.

Using the Flutter DevTools i noticed that:
3 post calls:

  1. getSystemDateAndTime -> response 200

<?xml version="1.0" encoding="UTF-8"?><s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header/><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetSystemDateAndTime xmlns="http://www.onvif.org/ver10/device/wsdl"/></s:Body></s:Envelope>

  1. GetServices -> response 500
    request:
    <?xml version="1.0" encoding="UTF-8"?><s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"><s:Header/><s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><GetServices xmlns="http://www.onvif.org/ver10/device/wsdl"><IncludeCapability>true</IncludeCapability></GetServices></s:Body></s:Envelope>
    response:
    <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:chan="http://schemas.microsoft.com/ws/2005/02/duplex" xmlns:wsa5="http://www.w3.org/2005/08/addressing" xmlns:c14n="http://www.w3.org/2001/10/xml-exc-c14n#" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" xmlns:wsc="http://schemas.xmlsoap.org/ws/2005/02/sc" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:ns2="http://www.onvif.org/ver10/pacs" xmlns:xmime="http://tempuri.org/xmime.xsd" xmlns:xop="http://www.w3.org/2004/08/xop/include" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:wsrfbf="http://docs.oasis-open.org/wsrf/bf-2" xmlns:wstop="http://docs.oasis-open.org/wsn/t-1" xmlns:wsrfr="http://docs.oasis-open.org/wsrf/r-2" xmlns:ns1="http://www.onvif.org/ver10/accesscontrol/wsdl" xmlns:ns3="http://www.onvif.org/ver10/actionengine/wsdl" xmlns:tad="http://www.onvif.org/ver10/analyticsdevice/wsdl" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:timg="http://www.onvif.org/ver20/imaging/wsdl" xmlns:tptz="http://www.onvif.org/ver20/ptz/wsdl" xmlns:trc="http://www.onvif.org/ver10/recording/wsdl" xmlns:trt="http://www.onvif.org/ver10/media/wsdl" xmlns:trv="http://www.onvif.org/ver10/receiver/wsdl" xmlns:tse="http://www.onvif.org/ver10/search/wsdl" xmlns:vifsvr="http://www.onvif.org/ver10/events/wsdl/PullPointSubscriptionBinding" xmlns:vifsvr10="http://www.onvif.org/ver20/analytics/wsdl/AnalyticsEngineBinding" xmlns:vifsvr2="http://www.onvif.org/ver10/events/wsdl/EventBinding" xmlns:tev="http://www.onvif.org/ver10/events/wsdl" xmlns:vifsvr3="http://www.onvif.org/ver10/events/wsdl/SubscriptionManagerBinding" xmlns:vifsvr4="http://www.onvif.org/ver10/events/wsdl/NotificationProducerBinding" xmlns:vifsvr5="http://www.onvif.org/ver10/events/wsdl/NotificationConsumerBinding" xmlns:vifsvr6="http://www.onvif.org/ver10/events/wsdl/PullPointBinding" xmlns:vifsvr7="http://www.onvif.org/ver10/events/wsdl/CreatePullPointBinding" xmlns:vifsvr8="http://www.onvif.org/ver10/events/wsdl/PausableSubscriptionManagerBinding" xmlns:wsnt="http://docs.oasis-open.org/wsn/b-2" xmlns:vifsvr9="http://www.onvif.org/ver20/analytics/wsdl/RuleEngineBinding" xmlns:tan="http://www.onvif.org/ver20/analytics/wsdl" xmlns:ter="http://www.onvif.org/ver10/error" xmlns:tns1="http://www.onvif.org/ver10/topics"><SOAP-ENV:Header></SOAP-ENV:Header><SOAP-ENV:Body><SOAP-ENV:Fault><SOAP-ENV:Code><SOAP-ENV:Value>ter:Unauthorized</SOAP-ENV:Value><SOAP-ENV:Subcode><SOAP-ENV:Value>ter:Unauthorized</SOAP-ENV:Value></SOAP-ENV:Subcode></SOAP-ENV:Code><SOAP-ENV:Reason><SOAP-ENV:Text xml:lang="en">**Sender not Authorized**</SOAP-ENV:Text></SOAP-ENV:Reason></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
  2. GetCapabilities -> response 500 (like the previous point)

At this point i compared this connection phase with "my" v2.0.13+19 version.
Here the request also contains authentication in the header:

<?xml version="1.0" encoding="UTF-8"?> <s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing"> <s:Header> <Security xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1"> <UsernameToken> <Username>replaced</Username> <Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">replaced=</Password> <Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">replaced==</Nonce> <Created xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">2023-03-13T22:41:41.000143Z </Created> </UsernameToken> </Security> </s:Header> <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <GetServices xmlns="http://www.onvif.org/ver10/device/wsdl"> <IncludeCapability>true</IncludeCapability> </GetServices> </s:Body> </s:Envelope>

In conclusion i think this famous "Connection closed while receiving data" error is simply an authentication problem.

I hope it could be useful. Let me know if you find a match.
Thanks in advance

@faithoflifedev
Copy link
Owner

@LODYZ, I think we have some progress here. It looks like the device you are using requires an authenticated header for the GetServices request, while all the devices that I've tested to date do not require this. I've now published v2.1.0-dev.10 that adds the authenticated header when making the request.

Let me know if this resolves the issue for you.

@LODYZ
Copy link
Author

LODYZ commented Mar 14, 2023

Hi @faithoflifedev, problem solved 🎉

@LODYZ LODYZ closed this as completed Mar 14, 2023
@faithoflifedev faithoflifedev pinned this issue Mar 15, 2023
@faithoflifedev
Copy link
Owner

Hi @LODYZ,

I've finally gotten access to a device that allowed me to recreate this issue for a specific Onvif command. For the media2.getStreamUri request, the Onvif supplied wsdl description wasn't updated properly to match the official spec - https://www.onvif.org/specs/srv/media/ONVIF-Media2-Service-Spec.pdf - so the SOAP request the code was building was incorrect and some devices like the Lorex LNB4421SB throw a "Connection closed" error rather than the documented env:Sender - ter:InvalidArgVal that would actually be useful.

Even though this wasn't your specific issue, I'm adding this here so that the related issue is at least somewhat documented. The moral of the story is that there are errors in the spec documents and also bad spec implementations on devices that cause a double whammy for troubleshooting.

The next release will have the "Connection closed" issue resolved for and media2.getStreamUri requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants