Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ticker is Unable to connect. #44

Open
vijay-arwapally opened this issue Jul 18, 2022 · 5 comments
Open

Ticker is Unable to connect. #44

vijay-arwapally opened this issue Jul 18, 2022 · 5 comments

Comments

@vijay-arwapally
Copy link

Unable to connect to Ticker

Sample code being used.

Error
Connection error: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (400 - BadRequest))
Connection closed: 1006 - connection was closed uncleanly (WebSocket connection upgrade failed (400 - BadRequest))

Additional context
Add any other context about the problem here.

@ssheikh098
Copy link

ssheikh098 commented Jul 31, 2022

Hello @vijay-arwapally ,

I think you need to apply 2 changes.

image

replace with

import urllib.parse
image

In the python package of zerodha - KiteTicket class / file name ticker.py change word access_token to enctoken
image

replace with

image

Please note the second change will be replaced if you update kite package in future. so we might need to apply this again each time we upgrade kite package.

@PrajwalShenoy
Copy link

This worked for me, thanks

@ashishanand7
Copy link

Resolved. Thanks

@rushiagr
Copy link

rushiagr commented Oct 21, 2023

This is the hack with current code base:

jugaad-trader diff:

diff --git a/jugaad_trader/zerodha.py b/jugaad_trader/zerodha.py
index f39e44a..fbc44a7 100644
--- a/jugaad_trader/zerodha.py
+++ b/jugaad_trader/zerodha.py
@@ -13,6 +13,7 @@ import pickle
 import requests
 import click
 from six.moves.urllib.parse import urljoin
+import urllib.parse

 from kiteconnect import KiteConnect, KiteTicker
 import kiteconnect.exceptions as ex
@@ -50,7 +51,7 @@ class ZerodhaTicker(KiteTicker):

         uid = int(time.time()) * 1000
         self.socket_url = "{root}?api_key=kitefront&user_id={user_id}&enctoken={enc_token}&uid={uid}&user-agent=kite3-web&version=2.4.0".format(
-            root=self.ROOT_URI, user_id=user_id, enc_token=enc_token, uid=uid
+            root=self.ROOT_URI, user_id=user_id, enc_token=urllib.parse.quote_plus(enc_token), uid=uid
         )

The changes to pykiteconnect remains the same as above by @ssheikh098

@suri2501
Copy link

suri2501 commented Feb 4, 2024

Zerodha has changes the root for WebSocket.
root='wss://ws.kite.trade'

Please refer to this video for solution.
https://www.youtube.com/watch?v=_9C3FzqG-K8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants