vshymanskyy / blynk-library-python

Blynk library for Python. Works with Python 2, Python 3, MicroPython.
https://blynk.io/
MIT License
281 stars 97 forks source link

#corrected funnction for blynk connection issue with the blynklib.py file it has issue in connect self function #80

Open Gteck55 opened 6 months ago

Gteck55 commented 6 months ago

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()
ebolisa commented 6 months ago

@Gteck55 Could you please format the code lines so they can be seen better?