25

Im trying to create simple python code that would communicate with 9kw.eu captcha solving service through their api https://www.9kw.eu/api.html#apisubmit-tab. Basically I'm sending base64 encoded image with some keys:values and response from server should be number like: 58952554, but I'm only getting

<response[200]>

Which should mean that the server got my data, but im not getting anything else. I'm able to get the right result with simple html form:

    <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>

This is the python code, which should do the same thing:

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 for any help.

1
  • This is documented on the first snippet, on the home page, of the requests package. On a sidenote, in future questions, please try to outline what you're trying to achieve more clearly; a Request object has many properties, all of which may be useful in various contexts.
    – Jules
    Apr 11, 2017 at 19:06

3 Answers 3

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

Here, r is the whole response object which has many attributes. I guess, you only need r.text. So, you can just use:

print(r.text) 
0
18

You're looking for the response of the request:

print(r.text)

In this way you'll have the plain text response.

1
  • you are a life-saver. I am looking for this code for hours. Thanks!!
    – BARIS KURT
    Mar 31, 2022 at 21:50
2

get json output by:

r.json()

and response_code by:

r.status_code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.