Hello,
opcua-asyncio version stops with error on connection to server step in async with Client(url=url) as client
. At the same time opcua works well.
import asyncio
import sys
sys.path.insert(0, "..")
import logging
from asyncua import Client, Node, ua
logging.basicConfig(level=logging.DEBUG)
_logger = logging.getLogger('asyncua')
async def main():
url = 'opc.tcp://localhost:4990/FactoryTalkLinxGateway1'
try:
async with Client(url=url) as client:
root = client.get_root_node()
_logger.info('Objects node is: %r', root)
except Exception:
_logger.exception('error')
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.set_debug(True)
loop.run_until_complete(main())
loop.close()
Debug info:
INFO:asyncua.client.client:connect
INFO:asyncua.client.ua_client.UaClient:opening connection
DEBUG:asyncio:Get address info localhost:4990, type=<SocketKind.SOCK_STREAM: 1>
DEBUG:asyncio:Getting address info localhost:4990, type=<SocketKind.SOCK_STREAM: 1> took 0.000ms: [(<AddressFamily.AF_INET6: 23>, <SocketKind.SOCK_STREAM: 1>, 0, '', ('::1', 4990, 0, 0)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 0, '', ('127.0.0.1', 4990))]
DEBUG:asyncio:poll took 0.000 ms: 1 events
DEBUG:asyncio:connect <socket.socket fd=256, family=AddressFamily.AF_INET6, type=SocketKind.SOCK_STREAM, proto=0> to ('::1', 4990, 0, 0)
DEBUG:asyncio:poll took 0.000 ms: 1 events
DEBUG:asyncio:<socket.socket fd=256, family=AddressFamily.AF_INET6, type=SocketKind.SOCK_STREAM, proto=0, laddr=('::1', 50124, 0, 0), raddr=('::1', 4990, 0, 0)> connected to localhost:4990: (<_SelectorSocketTransport fd=256 read=polling write=<idle, bufsize=0>>, <asyncua.client.ua_client.UASocketProtocol object at 0x037A7FF0>)
DEBUG:asyncio:poll 4000.000 ms took 0.000 ms: 1 events
INFO:asyncua.client.ua_client.UASocketProtocol:open_secure_channel
DEBUG:asyncua.client.ua_client.UASocketProtocol:Sending: OpenSecureChannelRequest(TypeId:FourByteNodeId(i=446), RequestHeader:RequestHeader(AuthenticationToken:TwoByteNodeId(i=0), Timestamp:2019-02-24 08:55:37.973007, RequestHandle:1, ReturnDiagnostics:0, AuditEntryId:None, TimeoutHint:1000, AdditionalHeader:ExtensionObject(TypeId:TwoByteNodeId(i=0), Encoding:0, None bytes)), Parameters:OpenSecureChannelParameters(ClientProtocolVersion:0, RequestType:0, SecurityMode:1, ClientNonce:b'', RequestedLifetime:3600000))
DEBUG:asyncio:poll 4000.000 ms took 0.000 ms: 1 events
INFO:asyncua.client.ua_client.UaClient:create_session
DEBUG:asyncua.client.ua_client.UASocketProtocol:Sending: CreateSessionRequest(TypeId:FourByteNodeId(i=461), RequestHeader:RequestHeader(AuthenticationToken:TwoByteNodeId(i=0), Timestamp:2019-02-24 08:55:37.975007, RequestHandle:2, ReturnDiagnostics:0, AuditEntryId:None, TimeoutHint:10, AdditionalHeader:ExtensionObject(TypeId:TwoByteNodeId(i=0), Encoding:0, None bytes)), Parameters:CreateSessionParameters(ClientDescription:ApplicationDescription(ApplicationUri:urn:freeopcua:client, ProductUri:urn:freeopcua.github.io:client, ApplicationName:LocalizedText(Encoding:2, Locale:None, Text:Pure Python Async. Client), ApplicationType:1, GatewayServerUri:None, DiscoveryProfileUri:None, DiscoveryUrls:[]), ServerUri:None, EndpointUrl:opc.tcp://localhost:4990/FactoryTalkLinxGateway1, SessionName:Pure Python Async. Client Session1, ClientNonce:b'\xe4IK\x81E\x10\xdf&\xff\xdaY\xc5\x9cc\xa1\xa6\xc0\xff\xbd\xcbN\xff\x91\x12J\xacJ\xbe\x9b\xba\xe7\x95', ClientCertificate:None, RequestedSessionTimeout:3600000, MaxResponseMessageSize:0))
DEBUG:asyncio:poll 10000.000 ms took 0.000 ms: 1 events
INFO:asyncua.client.client:find_endpoint [EndpointDescription(EndpointUrl:opc.tcp://localhost:4990/FactoryTalkLinxGateway1, Server:ApplicationDescription(ApplicationUri:urn:TEMP09-81OV7KU9:FactoryTalk Linx Gateway OPC UA Server, ProductUri:urn:FactoryTalk Linx Gateway OPC UA Server, ApplicationName:LocalizedText(Encoding:3, Locale:en, Text:FactoryTalkLinxGateway), ApplicationType:0, GatewayServerUri:None, DiscoveryProfileUri:None, DiscoveryUrls:['opc.tcp://localhost:4990/FactoryTalkLinxGateway1']), ServerCertificate:[...cuted...] , SecurityMode:1, SecurityPolicyUri:http://opcfoundation.org/UA/SecurityPolicy#None, UserIdentityTokens:[UserTokenPolicy(PolicyId:Anonymous_Policy, TokenType:0, IssuedTokenType:None, IssuerEndpointUrl:None, SecurityPolicyUri:None)], TransportProfileUri:http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary, SecurityLevel:11)] <MessageSecurityMode.None_: 1> 'http://opcfoundation.org/UA/SecurityPolicy#None'
INFO:asyncua.client.ua_client.UaClient:activate_session
DEBUG:asyncua.client.ua_client.UASocketProtocol:Sending: ActivateSessionRequest(TypeId:FourByteNodeId(i=467), RequestHeader:RequestHeader(AuthenticationToken:ByteStringNodeId(b=b'\x1an]\xd6[\x04&\x95!w\xb5\x98\xb53\xa0g2\A<\xc1\xd8\xb9\x10\x9e\x0b\xdf\x10\xea\x00,j'), Timestamp:2019-02-24 08:55:37.979007, RequestHandle:3, ReturnDiagnostics:0, AuditEntryId:None, TimeoutHint:10, AdditionalHeader:ExtensionObject(TypeId:TwoByteNodeId(i=0), Encoding:0, None bytes)), Parameters:ActivateSessionParameters(ClientSignature:SignatureData(Algorithm:http://www.w3.org/2000/09/xmldsig#rsa-sha1, Signature:b''), ClientSoftwareCertificates:[], LocaleIds:['en'], UserIdentityToken:AnonymousIdentityToken(PolicyId:Anonymous_Policy), UserTokenSignature:SignatureData(Algorithm:None, Signature:None)))
DEBUG:asyncio:poll 10000.000 ms took 78.000 ms: 1 events
WARNING:asyncua.client.ua_client.UASocketProtocol:ServiceFault from server received in response to ActivateSessionRequest
ERROR:asyncua:error
Traceback (most recent call last):
File "C:\Users\Labuser\git\opcua-asyncio\examples\client-minimal_my.py", line 14, in main
async with Client(url=url) as client:
File "..\asyncua\client\client.py", line 65, in aenter
await self.connect()
File "..\asyncua\client\client.py", line 209, in connect
await self.activate_session(username=self._username, password=self._password, certificate=self.user_certificate)
File "..\asyncua\client\client.py", line 404, in activate_session
return await self.uaclient.activate_session(params)
File "..\asyncua\client\ua_client.py", line 272, in activate_session
data = await self.protocol.send_request(request)
File "..\asyncua\client\ua_client.py", line 124, in send_request
self.check_answer(data, " in response to " + request.class.name)
File "..\asyncua\client\ua_client.py", line 133, in check_answer
hdr.ServiceResult.check()
File "..\asyncua\ua\uatypes.py", line 224, in check
raise UaStatusCodeError(self.value)
asyncua.ua.uaerrors._auto.BadTimeout: The operation timed out.(BadTimeout)
DEBUG:asyncio:Close <_WindowsSelectorEventLoop running=False closed=False debug=True>
ERROR:asyncio:Task was destroyed but it is pending!
source_traceback: Object created at (most recent call last):
File "C:\Users\Labuser\git\opcua-asyncio\examples\client-minimal_my.py", line 24, in
loop.run_until_complete(main())
File "C:\Users\Labuser\AppData\Local\Programs\Python\Python37-32\lib\asyncio\base_events.py", line 571, in run_until_complete
self.run_forever()
File "C:\Users\Labuser\AppData\Local\Programs\Python\Python37-32\lib\asyncio\base_events.py", line 539, in run_forever
self._run_once()
File "C:\Users\Labuser\AppData\Local\Programs\Python\Python37-32\lib\asyncio\base_events.py", line 1767, in _run_once
handle._run()
File "C:\Users\Labuser\AppData\Local\Programs\Python\Python37-32\lib\asyncio\events.py", line 88, in _run
self._context.run(self._callback, *self._args)
File "C:\Users\Labuser\git\opcua-asyncio\examples\client-minimal_my.py", line 14, in main
async with Client(url=url) as client:
File "..\asyncua\client\client.py", line 65, in aenter
await self.connect()
File "..\asyncua\client\client.py", line 204, in connect
await self.create_session()
File "..\asyncua\client\client.py", line 340, in create_session
self._renew_channel_task = self.loop.create_task(self._renew_channel_loop())
task: <Task pending coro=<Client._renew_channel_loop() running at ..\asyncua\client\client.py:353> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x0383E710>()] created at C:\Users\Labuser\AppData\Local\Programs\Python\Python37-32\lib\asyncio\base_events.py:396> created at ..\asyncua\client\client.py:340>