I am using the DLMS/COSEM python library to read data from a meter througth IPv6 address by UDP. However, I get an error: ''[Errno -9] Address family for hostname not supported "
Python library not suport IPv6 througth UDP connection?
You are right. Support for IP v6 is now added to Gurux.Net.Pyhon version 1.0.10.
It's on the Github now. Some tests are run and it'll publish to pypi latest tomorrow.
I have ran some tests with the new release and still not working. However, i made some changes in lib and worked:
changes:
def open(self):
"""Opens the connection. Protocol, Port and HostName must be set, before
calling the Open method."""
self.close()
try:
with self.__syncBase.getSync():
self.__syncBase.resetLastPosition()
self.__notifyMediaStateChange(MediaState.OPENING)
if ipaddress.ip_address(self.hostName).version is 4:
if self.protocol == NetworkType.TCP:
self.__socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.__socket.connect((self.__host_name, self.__port))
else:
self.__socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.__socket.connect((self.__host_name, self.__port))
else:
if self.protocol == NetworkType.TCP:
self.__socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM, 0)
self.__socket.connect((self.__host_name, self.__port, 0, 0))
else:
self.__socket = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, 0)
self.__socket.connect((self.__host_name, self.__port, 0, 0))
self.__notifyMediaStateChange(MediaState.OPEN)
self.__thread = threading.Thread(target=self.__listenerThread)
self.__thread.start()
except Exception as e:
self.close()
raise e
This was improved in version 1.0.10. Are you using that? Your changes are great, but the problem in ipaddress.ip_address is that it's not implemented for Python 2.7 and for this reason we can't use it.
Hi,
Hi,
You are right. Support for IP v6 is now added to Gurux.Net.Pyhon version 1.0.10.
It's on the Github now. Some tests are run and it'll publish to pypi latest tomorrow.
BR,
Mikko
Hello Mikko,
Hello Mikko,
I have ran some tests with the new release and still not working. However, i made some changes in lib and worked:
changes:
def open(self):
"""Opens the connection. Protocol, Port and HostName must be set, before
calling the Open method."""
self.close()
try:
with self.__syncBase.getSync():
self.__syncBase.resetLastPosition()
self.__notifyMediaStateChange(MediaState.OPENING)
if ipaddress.ip_address(self.hostName).version is 4:
if self.protocol == NetworkType.TCP:
self.__socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.__socket.connect((self.__host_name, self.__port))
else:
self.__socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.__socket.connect((self.__host_name, self.__port))
else:
if self.protocol == NetworkType.TCP:
self.__socket = socket.socket(socket.AF_INET6, socket.SOCK_STREAM, 0)
self.__socket.connect((self.__host_name, self.__port, 0, 0))
else:
self.__socket = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, 0)
self.__socket.connect((self.__host_name, self.__port, 0, 0))
self.__notifyMediaStateChange(MediaState.OPEN)
self.__thread = threading.Thread(target=self.__listenerThread)
self.__thread.start()
except Exception as e:
self.close()
raise e
Hi,
Hi,
This was improved in version 1.0.10. Are you using that? Your changes are great, but the problem in ipaddress.ip_address is that it's not implemented for Python 2.7 and for this reason we can't use it.
Can you tell what failed so we can try to fix it?
BR,
Mikko
Changes in libs:
Changes in libs:
if self.protocol == NetworkType.TCP:
self.__socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.__socket = socket.socket(GXNet.__getInet(self.__host_name), socket.SOCK_STREAM)
self.__socket.connect((self.__host_name, self.__port))
else:
self.__socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.__socket.connect((GXNet.__getInet(self.__host_name), self.__port)
In the UDP side, it should be:
else:
self.__socket = socket.socket(GXNet.__getInet(self.__host_name), socket.SOCK_DGRAM)
self.__socket.connect((self.__host_name, self.__port))
This is working (:
Hi Jonas,
Hi Jonas,
Thank you from this info. :-) This is now fixed this and new version is released.
BR,
Mikko