Error 401 sending recaptcha token with requests

谁都会走 提交于 2021-02-10 22:18:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!