lc-core/scripts/simpleTest.py

39 lines
960 B
Python
Raw Normal View History

2020-07-03 12:54:21 -04:00
import http.client
import json
conn = http.client.HTTPConnection('localhost', 8888)
conn.request("GET", "/v1/token?email=test")
response = conn.getresponse()
responseStr = response.read()
user = json.loads(responseStr)
2020-07-04 15:18:20 -04:00
token = user["token"]
2020-07-03 12:54:21 -04:00
params = """{
"level": "medium",
"media": "image/png",
"input_type": "text"
}"""
2020-07-04 15:18:20 -04:00
def getCaptcha():
conn.request("POST", "/v1/captcha", body=params, headers={'access-token': user["token"]})
response = conn.getresponse()
2020-07-03 12:54:21 -04:00
2020-07-04 15:18:20 -04:00
if response:
responseStr = response.read()
return json.loads(responseStr)
2020-07-03 12:54:21 -04:00
2020-07-04 15:18:20 -04:00
def postAnswer(captchaId, ans):
reply = {"answer": ans, "id" : captchaId}
2020-07-03 12:54:21 -04:00
conn.request("POST", "/v1/answer", json.dumps(reply))
response = conn.getresponse()
if response:
2020-07-04 15:18:20 -04:00
return response.read()
2020-07-03 12:54:21 -04:00
print(responseStr)
2020-07-04 15:18:20 -04:00
for i in range(0, 10000):
captcha = getCaptcha()
#print(captcha)
captchaId = captcha["id"]
print(i, postAnswer(captchaId, "xyz"))