Skip to content
This repository was archived by the owner on Apr 26, 2026. It is now read-only.
This repository was archived by the owner on Apr 26, 2026. It is now read-only.

response 41 after sending 42 auth session #4

Closed

Description

@vladdd183

Hello! I'm doing web socket reverse engineering too, ran into a problem, I'm doing the same as you:

  1. I connect to the web socket
  2. I get "0 sid..."
  3. Send "40" in response
  4. Receive message "40 sid..."
  5. I reply with "42 auth session"
  6. I get "41" in reply
async def process_message(message, websocket):
    print(message)
    if message.startswith('0{"sid":"'):
        message = message.lstrip("0")
        data = json.loads(message)
        print("got 0 sid send 40 ")
        await websocket.send("40")
    elif message == "2":
        print("got 2 send 3")
        await websocket.send("3")
    elif message.startswith('40{"sid":"'):
        print("got 40 sid send session")
        data = r"""42["auth",{"session":"a:4:{s:10:"session_id";s:32:"c53eec05c6f8a8be2d134d4fd55266f8";s:10:"ip_address";s:14:"46.138.176.190";s:10:"user_agent";s:101:"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36";s:13:"last_activity";i:1707850603;}9f383935faff5a86bc1658bbde8c61e7","isDemo":1,"uid":72038016,"platform":3}]"""
        await websocket.send(data)

I don't understand what this is about, could you please advise me?
image

Activity

  1. theshadow76 commented on Feb 13, 2024

    @theshadow76
    Member

    Yes, same here, I am getting the error of 41, I am going to try using webdriver, probably it's beeing blocked, so I will try that, but I am not giving up on this api that for sure :)

  2. theshadow76 commented on Feb 13, 2024

    @theshadow76
    Member

    I'll tell you what happened, and if I recomend it.

  3. vladdd183 commented on Feb 13, 2024

    @vladdd183
    Author

    Okay, thank you very much. I'll keep trying and I'll tell you too if I find a solution :)

  4. vladdd183 commented on Feb 13, 2024

    @vladdd183
    Author

    image
    image
    image

    @theshadow76
    I've made progress.
    It was the backslashes before the inverted commas.
    Now we're getting binary data
    However, after the first data is received, the disconnect occurs.

    data = r'42["auth",{"session":"a:4:{s:10:\"session_id\";s:32:\"c53eec05c6f8a8be2d134d4fd55266f8\";s:10:\"ip_address\";s:14:\"46.138.176.190\";s:10:\"user_agent\";s:101:\"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36\";s:13:\"last_activity\";i:1707850603;}9f383935faff5a86bc1658bbde8c61e7","isDemo":1,"uid":72038016,"platform":3}]'

    This is what the data should look like

    Also you need "origin" header with website url, in my case: https://pocket-link19.co

                async with websockets.connect(
                    "wss://api-eu.po.market/socket.io/?EIO=4&transport=websocket",
                    extra_headers={
                        "Origin": "https://pocket-link19.co",
                    },
                ) as websocket:

    i am using "websockets" python library

    so, to all you need:

    1. Backslashes
    2. Origin header
  5. vladdd183 commented on Feb 13, 2024

    @vladdd183
    Author

    i made a little mistake with reconnection, now it works good.
    Also you need only Backslashes and Origin Header

  6. theshadow76 commented on Feb 14, 2024

    @theshadow76
    Member

    Thank you very much!

  7. theshadow76 commented on Feb 14, 2024

    @theshadow76
    Member

    I'll adjust the code

  8. theshadow76 commented on Feb 14, 2024

    @theshadow76
    Member

    @vladdd183
    Hello!
    Sorry to bother you again, but here:

    import urllib
    import websocket
    from pocketoptionapi.constants import REGION
    import threading
    import logging
    import ssl
    
    class WebSocketClient:
        def __init__(self, url, pocket_api_instance=None):
            self.url = url
            self.pocket_api_instance = pocket_api_instance
            self.logger = logging.getLogger(__name__)
            self.logger.setLevel(logging.INFO)
            formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
    
            # Create file handler and add it to the logger
            file_handler = logging.FileHandler('pocket.log')
            file_handler.setFormatter(formatter)
            self.logger.addHandler(file_handler)
            self.header = "Origin: https://google.com"
            self.ws = websocket.WebSocketApp(self.url,
                                             on_open=self.on_open,
                                             on_message=self.on_message,
                                             on_error=self.on_error,
                                             on_close=self.on_close,
                                             header=[self.header])
            self.logger.info("Starting websocket client...")
    
        def on_message(self, ws, message):
            print(f"Message: {message}")
            self.logger.info(f"Recieved a message!: {message}")
    
            if str(message).startswith('0{"sid":'):
                ws.send("40")
            if str(message).startswith('40{"sid"'):
                data = r'42["auth",{"session":"a:4:{s:10:\"session_id\";s:32:\"da7a5a82c8f6c35a87b2ee31d4f5b3b4\";s:10:\"ip_address\";s:10:\"90.36.9.15\";s:10:\"user_agent\";s:120:\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 OP\";s:13:\"last_activity\";i:1707667599;}3a0058a58a6df5e7b49f652f8e4f8249","isDemo":0,"uid":27658142,"platform":1}]'
                print(f"Sent the auth messaage!: {data}")
                ws.send(data)
            
    
        def on_error(self, ws, error):
            print(error)
            self.logger.error(f"Got a error: {error}")
    
        def on_close(self, ws, close_status_code, close_msg):
            print("### closed ###")
            self.logger.warning(f"Connection closed, conections status_code: {close_status_code} and the message is: {close_msg}")
    
        def on_open(self, ws):
            print("Opened connection")
            self.logger.info("Opened!")
    
        def run(self):
            self.ws.run_forever()  # Use dispatcher for automatic reconnection
    
    ws = WebSocketClient(url="wss://api-l.po.market/socket.io/?EIO=4&transport=websocket")
    ws.run()

    I am getting this output:

    Opened connection
    Message: 0{"sid":"s-DtcnSjnIgXZFuoNKB7","upgrades":[],"pingInterval":25000,"pingTimeout":20000,"maxPayload":1000000}
    Message: 40{"sid":"aSAnWTMPfgSv-DKNNKCG"}
    Sent the auth messaage!: 42["auth",{"session":"a:4:{s:10:\"session_id\";s:32:\"da7a5a82c8f6c35a87b2ee31d4f5b3b4\";s:10:\"ip_address\";s:10:\"90.36.9.15\";s:10:\"user_agent\";s:120:\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 OP\";s:13:\"last_activity\";i:1707667599;}3a0058a58a6df5e7b49f652f8e4f8249","isDemo":0,"uid":27658142,"platform":1}]
    Message: 41
    ### closed ###
    

    looks like I am still getting that issue even tho I've added the hedears, but can you check if the data variable is the way it should be?
    Maybe it had to be formated in a diferent way.

    Let me know what you think!

  9. theshadow76 commented on Feb 14, 2024

    @theshadow76
    Member

    or if you would like to share your code, that would help alot to.
    thx

  10. vladdd183 commented on Feb 14, 2024

    @vladdd183
    Author
    self.header = "Origin: https://google.com"

    you shoud to set origin with site you using, not google
    try:
    https://po.trade/ (official link) or https://pocket-link19.co (mirror link)
    official is prefered, use mirror only if official link banned in your country

  11. theshadow76 commented on Feb 14, 2024

    @theshadow76
    Member

    Okey, let me check and I'll let you know

  12. vladdd183 commented on Feb 14, 2024

    @vladdd183
    Author

    I use "websockets" library and "anyio" for async, also "rich" for better print formating
    pip3 install websockets anyio rich

    this is the code (try to use second origin, that commented):

    import websockets
    import anyio
    from rich.pretty import pprint as print
    import json
    
    SESSION = r'session_string'
    
    
    async def websocket_client(url, pro):
        while True:
            try:
                async with websockets.connect(
                    url,
                    extra_headers={
                        "Origin": "https://pocket-link19.co",
                        # "Origin": "https://po.trade/"
                    },
                ) as websocket:
                    async for message in websocket:
                        await pro(message, websocket, url)
            except KeyboardInterrupt:
                exit()
            except Exception as e:
                print(e)
                print("Connection lost... reconnecting")
                await anyio.sleep(5)
        return True
    
    
    async def pro(message, websocket, url):
        # if byte data
        if type(message) == type(b""):
            # cut 100 first symbols of byte date to prevent spam
            print(str(message)[:100])
            return
        else:
            print(message)
    
        # Code to make order
        # data = r'42["openOrder",{"asset":"#AXP_otc","amount":1,"action":"call","isDemo":1,"requestId":14680035,"optionType":100,"time":20}]'
        # await websocket.send(data)
    
        if message.startswith('0{"sid":"'):
            print(f"{url.split('/')[2]} got 0 sid send 40 ")
            await websocket.send("40")
        elif message == "2":
            # ping-pong thing
            print(f"{url.split('/')[2]} got 2 send 3")
            await websocket.send("3")
    
        if message.startswith('40{"sid":"'):
            print(f"{url.split('/')[2]} got 40 sid send session")
            await websocket.send(SESSION)
    
    
    async def main():
        url = "wss://api-l.po.market/socket.io/?EIO=4&transport=websocket"
        await websocket_client(url, pro)
    
    
    if __name__ == "__main__":
        anyio.run(main)
  13. theshadow76 commented on Feb 14, 2024

    @theshadow76
    Member

    Thank you alot, I'll finish implementing it soon!
    Thanks for your help!!!

  14. 90 remaining items

  15. thacku commented on Jun 10, 2024

    @thacku

    https://discord.com/invite/Ge2yXheP

    It's invalid, can you provide new link to this

  16. theshadow76 commented on Jun 11, 2024

    @theshadow76
    Member

    https://discord.com/invite/Ge2yXheP

    It's invalid, can you provide new link to this

    https://discord.com/invite/XmQ6vzFQAT

  17. erfangnu commented on Jun 11, 2024

    @erfangnu

    @theshadow76 Hi, how can install this python package via pip?

  18. theshadow76 commented on Jun 11, 2024

    @theshadow76
    Member

    You need to use git, talk to us in discord https://discord.com/invite/XmQ6vzFQAT

  19. briancg42 commented on Jun 11, 2024

    @briancg42

    Thank you! ⚡

  20. sumittale5654 commented on Jul 24, 2024

    @sumittale5654

    can anyone tell how i resolve the pocketoptionapi module not found

  21. WanuPhiri commented on Sep 12, 2024

    @WanuPhiri

    I have a problem and I do not know how big or how to proceed.... I created a bot but when I run it I get this error. I think the pocketoptionapi modules are not well installed or not correct or the websockets issue. I need help to connect to Pocket Option

    WARNING:root:WebSocket connection closed: received 1005 (no status received [internal]); then sent 1005 (no status received [internal])
    ERROR:root:Error sending ping: received 1005 (no status received [internal]); then sent 1005 (no status received [internal])

    I do not have pocketoptionapi so I am trying to use ssid

    AttributeError: 'PocketOption' object has no attribute 'change_balance'
    ERROR:root:Error sending ping: received 1005 (no status received [internal]); then sent 1005 (no status received [internal])
    ERROR:root:Error sending ping: received 1005 (no status received [internal]); then sent 1005 (no status received [internal])
    botw

    from pocketoptionapi import global_value
    from pocketoptionapi.stable_api import PocketOption # Ensure this is correctly installed and imported
    import time
    import threading
    import asyncio
    import websockets
    import ssl

    Replace with your session ID

    ssid = "mc4i2u7c721ajl9u0sr779jq8q" # Your valid session ID

    Initialize PocketOption API with SSID

    API = PocketOption(ssid)

    Connect to the API

    check = API.connect()
    if not check:
    print("Connection failed.")
    exit()

    THIS IS JUST THE SECTION OF THE CODE WHERE I HAD TO INPUT SSID

    PLEASE HELP - THANK YOU

  22. theshadow76 commented on Sep 12, 2024

    @theshadow76
    Member

    I have a problem and I do not know how big or how to proceed.... I created a bot but when I run it I get this error. I think the pocketoptionapi modules are not well installed or not correct or the websockets issue. I need help to connect to Pocket Option

    WARNING:root:WebSocket connection closed: received 1005 (no status received [internal]); then sent 1005 (no status received [internal]) ERROR:root:Error sending ping: received 1005 (no status received [internal]); then sent 1005 (no status received [internal])

    I do not have pocketoptionapi so I am trying to use ssid

    AttributeError: 'PocketOption' object has no attribute 'change_balance' ERROR:root:Error sending ping: received 1005 (no status received [internal]); then sent 1005 (no status received [internal]) ERROR:root:Error sending ping: received 1005 (no status received [internal]); then sent 1005 (no status received [internal]) botw

    from pocketoptionapi import global_value from pocketoptionapi.stable_api import PocketOption # Ensure this is correctly installed and imported import time import threading import asyncio import websockets import ssl

    Replace with your session ID

    ssid = "mc4i2u7c721ajl9u0sr779jq8q" # Your valid session ID

    Initialize PocketOption API with SSID

    API = PocketOption(ssid)

    Connect to the API

    check = API.connect() if not check: print("Connection failed.") exit()

    THIS IS JUST THE SECTION OF THE CODE WHERE I HAD TO INPUT SSID

    PLEASE HELP - THANK YOU

    Hello! Please download the latest version here: https://github.com/theshadow76/PocketOptionAPI/releases/tag/v1.0.0

    and if you still have issues, please enter to our discord server: https://discord.gg/H8er9mbF4V

  23. theshadow76 commented on Sep 12, 2024

    @theshadow76
    Member

    can anyone tell how i resolve the pocketoptionapi module not found

    Please talk to us here: https://discord.gg/H8er9mbF4V

  24. WanuPhiri commented on Sep 22, 2024

    @WanuPhiri

    AttributeError: 'PocketOption' object has no attribute 'get_current_price'

    how can i resolve this error I am stuck. please help

  25. Mdbaizidtanvir commented on Oct 13, 2024

    @Mdbaizidtanvir

    how can i get this real time candle : " from pocketoptionapi.stable_api import PocketOption
    import time

    SSID: The session ID to authenticate with PocketOption

    ssid = r"""42["auth",{"session":"a:4:{s:10:"session_id";s:32:"47f30c18560908460f79392abb5e2ea0";s:10:"ip_address";s:15:"103.167.208.249";s:10:"user_agent";s:111:"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36";s:13:"last_activity";i:1728768861;}52f0fbcaac716f54f471b6030a4434b9","isDemo":0,"uid":72758516,"platform":2}]"""

    Initialize the PocketOption API, with demo set to True for safety

    API = PocketOption(ssid, demo=True)

    Connect to the API

    check = API.connect()

    if check:
    try:
    # Get the demo account balance
    print(f'Demo Balance: {API.get_balance()}')

        # Define the asset, candle period, and offset to retrieve candles
        asset = "EURUSD"
        current_time = int(time.time())  # Current time as timestamp
        offset = 120  # Get candles from 120 seconds before current time
        period = 60  # Candle size of 60 seconds (1 minute)
    
        print(f"You will get the candle from: {current_time - offset} to: {current_time}")
        print("------\n")
    
        # Fetch the candle data for the specified asset and time period
        candle = API.get_candles(active=asset, period=period, start_time=current_time - offset, count=6000, count_request=1)
        
        # Output the candle data
        print(candle)
    
        # Place a Buy order (Call)
        amount = 1  # Define how much you want to trade (e.g., 1 unit)
        expiration = 1  # Trade expiration time in minutes (example: 1 minute)
        action = 'call'  # "call" for buy/up, "put" for sell/down
    
        # Execute the buy order
        buy_order = API.buy(amount=amount, active=asset, action=action, expirations=expiration)
    
        # Output the result of the buy order
        if buy_order:
            print(f"Buy order placed successfully: {buy_order}")
        else:
            print("Failed to place the buy order.")
    
    except Exception as e:
        print(f"An error occurred: {e}")
    finally:
        # Disconnect from the API
        API.disconnect()
    

    else:
    print("Failed to connect to PocketOption API.")
    " " i am geting this error WARNING:root:Error occurred: 'isDemo'

  26. ALEXKODERODESSA commented on Dec 15, 2024

    @ALEXKODERODESSA

    Hi. I studied your project pocketoptionapi on githab. Tell me, did you manage to connect to pocketoption market data in real time? I have a ready-made program for automated trading on this broker. It remains only to connect directly to the broker's market data. At the moment, I use ticks from tradermade.com and I see a slight discrepancy in price movement compared to pocketoption. If you have a solution for connecting to real-time market data for pocketoption, then I will be very grateful for your help and will send you my program for automated trading. It will not be superfluous in the household. Here is a link to a video with my bot https://www.youtube.com/watch?v=wTnscfLpqjo&t=62s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions