2captcha / 2captcha-python

Python 3 package for easy integration with the API of 2captcha captcha solving service to bypass recaptcha, hcaptcha, сloudflare turnstile, funcaptcha, geetest and solve any other captchas.
https://pypi.org/project/2captcha-python
MIT License
550 stars 92 forks source link

2captcha not working for instagram #103

Closed alexander01202 closed 4 months ago

alexander01202 commented 4 months ago

Hello. I am trying to solve captcha on Instagram, however it doesn't work. I keep getting ERROR_CAPTCHA_UNSOLVABLE. I believe I need to pass the cookies, user-agent and proxy I used so that the person on the other end can solve it because instagram requires login to see the captcha.

2captcha defines multiple ways to define cookies which is very confusing. I do not know which one to use and what exactly is causing the error. I did open a ticket and was told this:

ERROR_CAPTCHA_UNSOLVABLE means we can't solve the captcha for you. Mostly this is caused by wrong sitekey or pageurl provided in your request.

First Method Second Method involves passing the name and value of cookies as a string with a NAME:VALUE pair separated with a semicolon. Eg "NAME1:VALUE1;NAME2:VALUE2;NAME3:VALUE3;NAME4:VALUE4;NAME5:VALUE5;"

Using the second method, this is what my Instagram cookies look like:

rur:"CCO\054674884fba1c56ec521d44bd308faf5b64f2580e0f35905487"; ds_user_id:67488458928; csrftoken:HYe5NDr
3WEcQJDcDVegN1fwRzcBRQSCY; sessionid:67488Hgo5WbWMQ2PAHrDqi7qyKKPQ; dpr:1.2; mid:Zo_raJ-ado5_8TkDd; wd:1540x786; ig_nrcb:1; datr:gqKAZ04Z; ig_did:26A6E35-F257991363C5; ps_n:1; ps_l:1

This is the sitekey I found on instagram: 6LdktRgnAAAAAFQ6icovYI2-masYLFjEFyzQzpix

PAGE_URL: https://www.instagram.com/challenge/?next=https%3A%2F%2Fwww.instagram.com%2Faccounts%2Fonetap%2F%3Fnext%3D%252F%26__coig_challenged%3D1

Here's my code:

solver = TwoCaptcha(self._2captcha_api_key)
session_cookies = requests.utils.dict_from_cookiejar(self.requests_session.cookies)

extra_cookie_options = {"domain": "instagram.com", "httpOnly": False}

# Using 1st Method
selenium_cookies = []
for name, value in session_cookies.items():
      cookie = {"name": name, "value": value}
      cookie.update(extra_cookie_options)
      selenium_cookies.append(cookie)

 # Using 2nd Method
 selenium_cookies = [f"{name}:{value}" for name, value in session_cookies.items()]
 solver_recaptcha_cookies = "; ".join(selenium_cookies)

print("solver_recaptcha_cookies ==> ", solver_recaptcha_cookies)
 result = solver.recaptcha(
       sitekey=site_key,
       url=page_url,
       cookies=solver_recaptcha_cookies,
       userAgent=self.current_account["useragent"],
       proxy={'type': 'HTTPS', 'uri': f'{self.current_account["proxy_username"]}:{self.current_account["proxy_password"]}@{self.current_account["proxy_ip"]}:{self.current_account["proxy_http_port"]}'})

I do not know if this is a cookies error or not, but I somehow believe so because you need to login to solve the captcha.

kratzky commented 4 months ago

Hi! Please contact our support team using this form: https://2captcha.com/support/tickets/new The issue is not related to cookies or User-Agent, it's in pageurl, our engineers will guide you how to find the valid value.