How to Send Recaptcha Token in Post Request (Python)

I'm trying to login to my leetcode account via a POST request (for a project). This is what I have so far:

import requests  
import os   
login\_url = ""  
s = requests.Session()  
res = s.get(')  
cookies = dict(res.cookies)  
csrftoken = cookies\['csrftoken'\]  
headers = {'Referer': url}  
data = {  
 'csrfmiddlewaretoken': csrftoken,  
 'login': os.environ\['LEETCODE\_USERNAME'\],  
 'password': os.environ\['LEETCODE\_PASSWORD'\],
 'next': '/problems/two-sum/',  
 'recaptcha\_token': (token from screenshot)  
}  
x = requests.post(login\_url, data=data, headers=headers, cookies=cookies)  
print(x.text)

This screenshot shows the payload: link

I tried to copy+paste that recaptcha_token in my data dictionary but I'm still getting this error:

{"recaptcha": {"error_type": "recaptcha_token_invalid", "error": "Something went wrong with reCAPTCHA."}}

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article