Can't Auhtenticate API Keys in Python

I tried the below code.

import websocket
import json
api_key='PKWS2NU9W6AI09PIEL3J'
secret_key='8IgZywxHrHuViIOT5/SKvZvy3159thn6SkzSKZcV'
ticker = 'MSFT'
ticker = 'Q.'+ticker
socket = "wss://alpaca.socket.polygon.io/stocks"
def on_open(ws):
    print('Market is Open')
    auth = {"action":"auth", "params": api_key}
    channel_data = {
        "action": "subscribe",
        "params": ticker
    }
    ws.send(json.dumps(auth))
    ws.send(json.dumps(channel_data))
def on_message(ws, message):
    print(message)
def on_close(ws):
    print("closed connection")    
ws = websocket.WebSocketApp(socket, on_open=on_open, on_message=on_message, on_close=on_close)
ws.run_forever()

But the API was not authenticating! Please help me!

Hi @Samar_Pratap_Singh
don’t put your credentials on internet forums (someone may see it and use it)
you should re-generate them in the alpaca website

you should not use websockets directly.
use streamconn as described here: https://github.com/alpacahq/alpaca-trade-api-python