1 Replies - 378 Views - Last Post: 08 October 2017 - 11:17 AM Rate Topic: -----

#1 digitalmatic7  Icon User is online

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-September 17

[Newbie API Problems] Troubleshooting 2Captcha API Script

Posted 06 October 2017 - 11:23 PM

Hey guys, glad to be a member, I've been learning Python for the past few weeks and I'm a bit out of my depth.

I'm stuck trying to connect to the 2captcha anti-captcha API.

Here's a look at the type of captcha I want to solve:

Posted Image

I have a pre-made script that I've been trying to modify.. it's meant for recaptcha2 but I'm just trying to solve a normal captcha. I'm wondering if I should just attempt to re-write it from scratch.. here's the code:

import requests
from time import sleep
# Add these values
API_KEY = 'mykeyexample423cf8fc00adfcca'  # Your 2captcha API KEY
site_key = ''  # site-key, read the 2captcha docs on how to get this
url = ''  # example url
s = requests.Session()
# here we post site key to 2captcha to get captcha ID (and we parse it here too)
captcha_id = s.post("http://2captcha.com/in.php?key={}&method=userrecaptcha&googlekey={}&pageurl={}".format(API_KEY, site_key, url)).text.split('|')[1]
# then we parse gresponse from 2captcha response
recaptcha_answer = s.get("http://2captcha.com/res.php?key={}&action=get&id={}".format(API_KEY, captcha_id)).text
print("solving ref captcha...")
while 'CAPCHA_NOT_READY' in recaptcha_answer:
    recaptcha_answer = s.get("http://2captcha.com/res.php?key={}&action=get&id={}".format(API_KEY, captcha_id)).text
recaptcha_answer = recaptcha_answer.split('|')[1]
# we make the payload for the post data here, use something like mitmproxy or fiddler to see what is needed
payload = {
    'key': 'value',
    'gresponse': recaptcha_answer  # This is the response from 2captcha, which is needed for the post request to go through.
# then send the post request to the url
response = s.post(url, payload)
# And that's all there is to it other than scraping data from the website, which is dynamic for every website.

I'm really lost.

The API is calling for the "BASE64_FILE is base64-encoded image body"

What does that even mean lol. I watched some tutorials on base64 but I feel even more confused now lol :rolleyes: Do they want a JPG version of the captcha?

I've isolated the URL where the captcha loads, I assumed I would be sending that over instead of an image but now I'm confused.

The site_key seems to be the string in the captcha screenshot after "?k=", it's a dynamically changing ID that I need to scrape as the captchas change correct?

"url" variable is just the page the captcha is located on?

Any help is much appreciated, I've been researching and trying to learn for about 8 hours today and still can't get it working :helpsmilie:

Is This A Good Question/Topic? 0
  • +

Replies To: [Newbie API Problems] Troubleshooting 2Captcha API Script

#2 woooee  Icon User is offline

  • D.I.C Head

Reputation: 45
  • View blog
  • Posts: 168
  • Joined: 21-November 12

Re: [Newbie API Problems] Troubleshooting 2Captcha API Script

Posted 08 October 2017 - 11:17 AM


format(API_KEY, site_key, url)
These are all empty strings. Print the url you are trying to get and make sure it is a valid one.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1