fix: resolve sign-in authentication failure#83
Open
milanbeherazyx wants to merge 1 commit intorongardF:mainfrom
Open
fix: resolve sign-in authentication failure#83milanbeherazyx wants to merge 1 commit intorongardF:mainfrom
milanbeherazyx wants to merge 1 commit intorongardF:mainfrom
Conversation
…d User-Agent The __auth method was using a bare requests.post() without a session or User-Agent header, causing TradingView to reject the request as bot traffic (returning rate_limit or silently failing). Changes: - Use requests.Session() to maintain cookies across requests - Add a browser-like User-Agent header to avoid bot detection - Visit the homepage before POST to /accounts/signin/ to pick up session cookies - Add Origin and Content-Type headers for proper CORS compliance - Add a single retry with 2s delay when rate-limited - Improve error logging to include the actual exception message - Remove duplicate json import
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
__authmethod inmain.pysilently fails witherror while signin, causing all authenticated users to fall back tounauthorized_user_token(no-login mode). This has been a widely reported issue affecting many users.Root Cause
The existing implementation uses a bare
requests.post()call without:User-Agentheader — TradingView flags the request as bot trafficrequests.Session()— No cookies are persisted, triggering rate-limit / anti-bot protectionOriginandContent-TypeheadersAs a result, TradingView returns a
rate_limiterror or silently rejects the sign-in request.Fix
Updated the
__authmethod to properly authenticate with TradingView:requests.Session()to maintain cookies across the GET → POST flowUser-Agentto avoid bot detectionGET /) before posting to/accounts/signin/to establish a proper sessionOriginandContent-Typeheaders for CORS complianceimport jsonstatementBefore (Broken)
After (Fixed)
Testing
Tested with valid TradingView credentials — login now succeeds and returns a proper JWT
auth_token. Data fetching with authenticated session works as expected (verified with NIFTY 15-min candles from NSE).Backward Compatibility
TvDatafeed(username, password)works the same wayTvDatafeed()) is unaffected