XaBbl4 / pytonconnect

Python SDK for TON Connect 2.0
Apache License 2.0
55 stars 18 forks source link

Connection link generation error #5

Open Vladikasik opened 8 months ago

Vladikasik commented 8 months ago

When using this method connector.connect(wallet) I'm always getting this error Bridge error -> READY_STATE_CONNECTING

XaBbl4 commented 7 months ago

Please send example in clean environment

SabyrAlymbekov commented 6 months ago

I also get this issue. This code from repo.


from datetime import datetime

from pytonconnect import TonConnect
from pytonconnect.exceptions import UserRejectsError

async def main():
    connector = TonConnect(
        manifest_url='https://raw.githubusercontent.com/XaBbl4/pytonconnect/main/pytonconnect-manifest.json')
    is_connected = await connector.restore_connection()
    print('is_connected:', is_connected)

    def status_changed(wallet_info):
        print('wallet_info:', wallet_info)
        unsubscribe()

    def status_error(e):
        print('connect_error:', e)

    unsubscribe = connector.on_status_change(status_changed, status_error)

    wallets_list = connector.get_wallets()
    print('wallets_list:', wallets_list)

    generated_url = await connector.connect(wallets_list)
    print('generated_url:', generated_url)

    print('Waiting 2 minutes to connect...')
    for i in range(120):
        await asyncio.sleep(1)
        if connector.connected:
            if connector.account.address:
                print('Connected with address:', connector.account.address)
            break

    if connector.connected:
        print('Sending transaction...')

        transaction = {
            'valid_until': int(datetime.now().timestamp()) + 900,
            'messages': [
                {
                    'address': '0:0000000000000000000000000000000000000000000000000000000000000000',
                    'amount': '1',
                },
                {
                    'address': '0:0000000000000000000000000000000000000000000000000000000000000000',
                    'amount': '1',
                }
            ]
        }

        try:
            result = await connector.send_transaction(transaction)
            print('Transaction was sent successfully')
            print(result)

        except Exception as e:
            if isinstance(e, UserRejectsError):
                print('You rejected the transaction')
            else:
                print('Unknown error:', e)

        print('Waiting 2 minutes to disconnect...')
        asyncio.create_task(connector.disconnect())
        for i in range(120):
            await asyncio.sleep(1)
            if not connector.connected:
                print('Disconnected')
                break

    print('App is closed')

if __name__ == '__main__':
    asyncio.get_event_loop().run_until_complete(main())```
SabyrAlymbekov commented 6 months ago

I also get this issue. This code from repo.

from datetime import datetime

from pytonconnect import TonConnect
from pytonconnect.exceptions import UserRejectsError

async def main():
    connector = TonConnect(
        manifest_url='https://raw.githubusercontent.com/XaBbl4/pytonconnect/main/pytonconnect-manifest.json')
    is_connected = await connector.restore_connection()
    print('is_connected:', is_connected)

    def status_changed(wallet_info):
        print('wallet_info:', wallet_info)
        unsubscribe()

    def status_error(e):
        print('connect_error:', e)

    unsubscribe = connector.on_status_change(status_changed, status_error)

    wallets_list = connector.get_wallets()
    print('wallets_list:', wallets_list)

    generated_url = await connector.connect(wallets_list)
    print('generated_url:', generated_url)

    print('Waiting 2 minutes to connect...')
    for i in range(120):
        await asyncio.sleep(1)
        if connector.connected:
            if connector.account.address:
                print('Connected with address:', connector.account.address)
            break

    if connector.connected:
        print('Sending transaction...')

        transaction = {
            'valid_until': int(datetime.now().timestamp()) + 900,
            'messages': [
                {
                    'address': '0:0000000000000000000000000000000000000000000000000000000000000000',
                    'amount': '1',
                },
                {
                    'address': '0:0000000000000000000000000000000000000000000000000000000000000000',
                    'amount': '1',
                }
            ]
        }

        try:
            result = await connector.send_transaction(transaction)
            print('Transaction was sent successfully')
            print(result)

        except Exception as e:
            if isinstance(e, UserRejectsError):
                print('You rejected the transaction')
            else:
                print('Unknown error:', e)

        print('Waiting 2 minutes to disconnect...')
        asyncio.create_task(connector.disconnect())
        for i in range(120):
            await asyncio.sleep(1)
            if not connector.connected:
                print('Disconnected')
                break

    print('App is closed')

if __name__ == '__main__':
    asyncio.get_event_loop().run_until_complete(main())```

I discovered that everything works on windows 11, but not on macOS Sonoma. It is strange...

gak3r commented 5 months ago

I encountered the SSLCertVerificationError issue when using the library. As a temporary workaround, you can patch aiohttp.ClientSession to ignore SSL certificate verification:

import ssl
import aiohttp
from aiohttp import ClientSession

# Create an SSL context that ignores certificate verification
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE

# Create a TCPConnector with the SSL context
connector = aiohttp.TCPConnector(ssl=ssl_context)

# Patch ClientSession to use the custom connector
original_init = ClientSession.__init__

def patched_init(self, *args, **kwargs):
    if 'connector' not in kwargs:
        kwargs['connector'] = connector
    original_init(self, *args, **kwargs)

ClientSession.__init__ = patched_init

This should help bypass the SSL verification issue for now.