blynk-library-python
blynk-library-python copied to clipboard
#corrected funnction for blynk connection issue with the blynklib.py file it has issue in connect self function
using below function it will fix the connection releted issue with the server just replace the existing function to this one in library file def connect(self): print('Connecting to %s:%d...' % (self.server, self.port)) try: addrinfo = socket.getaddrinfo(self.server, self.port) if not addrinfo: raise OSError("Failed to get address info")
(family, socktype, proto, _, sockaddr) = addrinfo[0]
s = socket.socket(family, socktype, proto)
s.connect(sockaddr)
try:
s.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
except:
pass
if self.insecure:
self.conn = s
else:
try:
import ussl
ssl_context = ussl
except ImportError:
import ssl
ssl_context = ssl.create_default_context()
self.conn = ssl_context.wrap_socket(s, server_hostname=self.server)
try:
self.conn.settimeout(SOCK_TIMEOUT)
except:
s.settimeout(SOCK_TIMEOUT)
BlynkProtocol.connect(self)
except Exception as e:
print(f"Connection error: {e}")
self.disconnect()
@Gteck55 Could you please format the code lines so they can be seen better?