mirror of
https://github.com/librecaptcha/lc-core.git
synced 2025-04-16 00:48:08 -04:00
Update simpleTest to latest API and solve before answering
Signed-off-by: hrj <harshad.rj@gmail.com>
This commit is contained in:
parent
d3a2c6fa35
commit
433621f046
@ -1,12 +1,8 @@
|
|||||||
import http.client
|
import http.client
|
||||||
import json
|
import json
|
||||||
|
import subprocess
|
||||||
|
|
||||||
conn = http.client.HTTPConnection('localhost', 8888)
|
conn = http.client.HTTPConnection('localhost', 8888)
|
||||||
conn.request("GET", "/v1/token?email=test")
|
|
||||||
response = conn.getresponse()
|
|
||||||
responseStr = response.read()
|
|
||||||
user = json.loads(responseStr)
|
|
||||||
token = user["token"]
|
|
||||||
|
|
||||||
params = """{
|
params = """{
|
||||||
"level": "medium",
|
"level": "medium",
|
||||||
@ -15,13 +11,25 @@ params = """{
|
|||||||
}"""
|
}"""
|
||||||
|
|
||||||
def getCaptcha():
|
def getCaptcha():
|
||||||
conn.request("POST", "/v1/captcha", body=params, headers={'access-token': user["token"]})
|
conn.request("POST", "/v1/captcha", body=params)
|
||||||
response = conn.getresponse()
|
response = conn.getresponse()
|
||||||
|
|
||||||
if response:
|
if response:
|
||||||
responseStr = response.read()
|
responseStr = response.read()
|
||||||
return json.loads(responseStr)
|
return json.loads(responseStr)
|
||||||
|
|
||||||
|
def getAndSolve(idStr):
|
||||||
|
conn.request("GET", "/v1/media?id=" + idStr)
|
||||||
|
response = conn.getresponse()
|
||||||
|
|
||||||
|
if response:
|
||||||
|
responseBytes = response.read()
|
||||||
|
with open("captcha.png", "wb") as f:
|
||||||
|
f.write(responseBytes)
|
||||||
|
ocrResult = subprocess.Popen("gocr captcha.png", shell=True, stdout=subprocess.PIPE)
|
||||||
|
ocrAnswer = ocrResult.stdout.readlines()[0].strip().decode()
|
||||||
|
return ocrAnswer
|
||||||
|
|
||||||
def postAnswer(captchaId, ans):
|
def postAnswer(captchaId, ans):
|
||||||
reply = {"answer": ans, "id" : captchaId}
|
reply = {"answer": ans, "id" : captchaId}
|
||||||
conn.request("POST", "/v1/answer", json.dumps(reply))
|
conn.request("POST", "/v1/answer", json.dumps(reply))
|
||||||
@ -33,6 +41,6 @@ def postAnswer(captchaId, ans):
|
|||||||
|
|
||||||
for i in range(0, 10000):
|
for i in range(0, 10000):
|
||||||
captcha = getCaptcha()
|
captcha = getCaptcha()
|
||||||
#print(captcha)
|
|
||||||
captchaId = captcha["id"]
|
captchaId = captcha["id"]
|
||||||
print(i, postAnswer(captchaId, "xyz"))
|
ans = getAndSolve(captchaId)
|
||||||
|
print(i, postAnswer(captchaId, ans))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user