问题
I tried to make a cart for this site: https://www.off---white.com/en/IT
When I tried to send values for the params of the cart, one of this params is a token of recaptcha. I tried manually to get the token using this project 'https://github.com/Cosmo3904/Recaptcha-Harvester-V2'
When I tried to make the request I pass all params:
token = 'recaptcha_token' #(I get it manually and expires every 110s)
payload = {"variant_id": "111380", "quantity": "1", 'g-recaptcha-response': token}
s = requests.Session()
resp2 = s.post("https://www.off---white.com/en/IT/orders/populate.json",headers=headers,data=payload)
print('STATUS CODE: ' + str(resp2.status_code))
unfortunately the response is every time 401, that means unauthorised. How can I solve this?
(To the session I pass headers and cookies so the page is right configured, I checked before trying login and it works)
回答1:
import cfscrape
s = requests.Session()
scraper = cfscrape.create_scraper(s)
scraper.get('https://www.off---white.com/en/IT', headers=headers)
url = 'https://www.off---white.com/en/IT/orders/populate.json'
r = scraper.post(url, data={'variant_id' : 'variant', 'quantity' : 1, 'g-recaptcha-response': token}, headers=headers)
Try with cfscrape.
来源:https://stackoverflow.com/questions/53516688/error-401-sending-recaptcha-token-with-requests