Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
5 views
in Python by (16.4k points)

Let me create a simple python code that would communicate with 9kw.eu captcha solving service through their API.

With some keys: values, I would be sending base64 encoded image and the response from the server should be in number: 58952554, But I'm not getting those numbers, instead, I'm getting

<response[200]>

This means that server had got my data, but I'm not getting anything else. 

With the help of HTML, I can able to get the right result,

    <form method="post" action="https://www.9kw.eu/index.cgi" enctype="multipart/form-data"> 

KEY:<br>

<input  name="apikey" value="APIKEY"><br>

ACTION<br>

<input  name="action" value="usercaptchaupload"><br>

FILE:<br>

<input name="file-upload-01" value="BASE64IMAGEDATAHERE"><br>

TOOL<br>

<input  name="source" value="htmlskript"><br>

ROTATE<br>

<input  name="rotate" value="1"><br>

Angle<br>

<input  name="angle" value="40"><br>

BASE64

<input  name="base64" value="1"><br>

Upload:<br>

<input type="submit" value="Upload and get ID">

</form>

The below program should do the same thing (Python code):

import requests

import time

#base64 image encoding

with open("funcaptcha1.png", "rb") as f:

    data = f.read()

    filekodovany = data.encode("base64")

    #captcha uploader

udajepost = {'apikey':'APIKEY','action':'usercaptchaupload','file-upload-01':filekodovany,'source':'pythonator','rotate':'1','angle':'40','base64':'1'}

headers = {'Content-Type':'multipart/form-data'}

r = requests.post('https://www.9kw.eu/index.cgi', data = udajepost)

print(r)

Thanks in advance :)

1 Answer

0 votes
by (26.4k points)
edited by

In the below code, 'r' is the whole response object which will have many attributes. I thought you need only r.text 

r = requests.post('https://www.9kw.eu/index.cgi', data = udajepost)

So, you can just use:

print(r.text)

If you want to become an expert in Python? Come, and Join: Python course 

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...