Writing a websocket client and eventsub subscription request in python, websocket recieves welcome message and functions seemingly correctly, but returns error 400, seen above, upon sending the subscription request:
async def listen():
url = "wss://eventsub.wss.twitch.tv/ws"
async with websockets.connect(url) as websocket:
msg = await websocket.recv()
msg_dic = json.loads(msg)
seshId = (msg_dic["payload"]["session"]["id"])
global sessionID
sessionID = seshId
asyncio.get_event_loop().run_until_complete(listen())
async def post_request():
async with aiohttp.ClientSession() as session:
response = await session.post(url="https://api.twitch.tv/helix/eventsub/subscriptions",
data=json.dumps({"type":"stream.online",
"version": "1",
"condition":{
"broadcaster_user_id": "------"},
"transport":{
"method":"websocket",
"session_id":sessionID}}),
headers={'Authorization': 'Bearer ---------',
'Client-Id': '----------',
"Content-Type": "application/json",})
print(await response.json())
asyncio.run(post_request())