0

Trying to convert from python request to chilkat2.HttpRequest :

import requests

data = {"username": "user","password": "pass","remember": "on"}

sign_in_url = 'https://www.tradingview.com/accounts/signin/'
signin_headers = {'Referer': 'https://www.tradingview.com'}

response = requests.post(url=sign_in_url, data=data, headers=signin_headers)
token = response.json()['user']['auth_token']

P.S. Cause no right username and password - will return status_code:200 b'{"error":"Invalid username or password","code":"invalid_credentials"}'

I have this:

http = chilkat2.Http()
req = chilkat2.HttpRequest()
req.AddParam("username","user")
req.AddParam("password","pass")
req.AddParam("remember","on")
req.Path = '/accounts/signin/'

req.HttpVerb = "POST"
http.FollowRedirects = True

http.SendCookies = True
http.SaveCookies = True
http.CookieDir = "memory"


resp = http.SynchronousRequest('www.tradingview.com',443,True,req)
print(http.LastErrorText)

But response - statusCode: 403 Forbidden What am I doing wrong?

IlyaK
  • 25
  • 1
  • 4

1 Answers1

1

See the tradingview.com API documentation: https://www.tradingview.com/rest-api-spec/#section/Authentication

You can see that an application/x-www-form-urlencoded POST is required.

It's easy to do with Chilkat. See this documentation showing how to send common HTTP request types: https://www.chilkatsoft.com/http_tutorial.asp

You'll want to send a request like this: https://www.chilkatsoft.com/http_post_url_encoded.asp

Chilkat Software
  • 1,405
  • 1
  • 9
  • 8
  • Cookies are not involved with this... – Chilkat Software Oct 05 '22 at 15:11
  • In general, cookies are typically used w/ interactive browser sessions. I've never seen a REST API using cookies. Perhaps some exist, but I see nothing about cookies in the TradingView API documenation, so why are you even worried about or bothering with Cookies?? – Chilkat Software Oct 05 '22 at 15:12