Overview
All the examples in this document are based on
Flask
、Tornado
、Django
framework。
Development environment
Item | Description |
---|---|
Compatibility | Compatible with python 2 & 3, but recommend to use python 2.7+ |
Dependency | Web framework(e.g. django , tornado , etc). Use pip install -r requirement.txt to install all the dependencies. |
Resources
Item | Description |
---|---|
Data communication flow chart | Data communication flow chart |
Download SDK | gt3-python-sdk |
Python SDK Installation
Download SDK
There are two ways to download SDK.
Use command line to get from Github
git clone https://github.com/GeeTeam/gt3-python-sdk.git |
Or download SDK manually
Get the latest SDK from Github: gt3-python-sdk (in .zip
format)
Import SDK
You might need
sudo
to execute the following commands.
When the development environment is ready, use the following commend to install SDK.
python setup.py install |
Use the following commend to import SDK.
from geetest import GeetestLib |
Configure key pair and modify the request
Configure key pair
Get your key pair from GeeTest Dashboard. The key pair consists of a public key(captcha ID) and a private key (KEY). Then, configure the key pair in the following path.
- Django:
/demo/django_demo/app/views.py
- Flask:
/demo/flask_demo/start.py
- Tornado:
/demo/tornado_demo/start.py
Modify the request (optional)
Variable | Description |
---|---|
user_id | User identification. If you concern about the risk of user information, you can preprocess (e.g. hashed) it. |
client_type | Type of client. Web (web browser for computers),h5 (mobile browser,include webview),native(native mobile app),unknown (unknow client type) |
ip_address | Client request for your server IP address, unknow means unknow IP address |
API example
The following examples are based on Tornado framework.
Captcha initialization
Initiate captcha via API1, get challenge
and set the status
class PcGetCaptchaHandler(SessionBaseHandler): |
Notice:
status
indicates captcha initialization. Status=1 refers to successful initialization, status=0 refers to downtime. Please store thestatus
, since it will be needed in secondary verification. In the demo above, session has been used to storestatus
.
Secondary verification (API2), including uptime and downtime
class PcValidateHandler(SessionBaseHandler): |
How to simulate the Failback mode? Please fill in an incorrect string (e.g. 123456789) for the captcha ID. Then, it will enter the Failback mode.
Run demo
You might need
sudo
to execute the following commands.
Run Flask demo
Use commend line to enter the path of the flask_demo folder, then executes the command:
$ python start.py |
To view the demo, please visit http://localhost:5000
in browser.
Run Tornado demo
Use commend line to enter the path of the tornado_demo folder, then executes the command:
$ python start.py |
To view the demo, please visithttp://localhost:8088
in browser.
Run Django demo
Use commend line to enter the path of the django_demo folder, then executes the command:
$ python manage.py runserver 0.0.0.0:8000 |
To view the demo, please visithttp://localhost:8000
in browser.
Troubleshooting: secondary verification failure
- SDK internal logic errors. Please check: a) whether
session
is stored and read successfully, b) whether the code could successfully process to the module which send a request to GeeTest server, c) check the return value of GeeTest server. - Multiple submission. The API which initiates the secondary verification is only available for one time.
- The
challenge
is inconsistent. Please ensure the consistency ofchallenge
during the whole verification process. - Check if
gt
andkey
in the code are correct in SDK. Please check if the parameters has been passed correctly. - Please provide
challenge
to our service team. They could help you to check the log.