forked from chyroc/WechatSogou
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test api in real network env (chyroc#104)
* test api in real network env * tmp * add log
- Loading branch information
Showing
6 changed files
with
76 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
from hashlib import md5 | ||
|
||
import requests | ||
|
||
|
||
class RClient(object): | ||
def __init__(self, username, password, soft_id, soft_key): | ||
self.base_params = { | ||
'username': username, | ||
'password': md5(password.encode('utf-8')).hexdigest(), | ||
'softid': soft_id, | ||
'softkey': soft_key, | ||
} | ||
self.headers = { | ||
'Connection': 'Keep-Alive', | ||
'Expect': '100-continue', | ||
'User-Agent': 'ben', | ||
} | ||
|
||
def rk_create(self, im, im_type, timeout=60): | ||
params = { | ||
'typeid': im_type, | ||
'timeout': timeout, | ||
} | ||
params.update(self.base_params) | ||
files = {'image': ('a.jpg', im)} | ||
r = requests.post('http://api.ruokuai.com/create.json', data=params, files=files, headers=self.headers) | ||
return r.json() | ||
|
||
def rk_report_error(self, im_id): | ||
params = { | ||
'id': im_id, | ||
} | ||
params.update(self.base_params) | ||
r = requests.post('http://api.ruokuai.com/reporterror.json', data=params, headers=self.headers) | ||
return r.json() | ||
|
||
|
||
def __identify_image_callback(img, code): | ||
try: | ||
username = os.environ['rk_username'] | ||
password = os.environ['rk_password'] | ||
id_ = os.environ['rk_id'] | ||
key = os.environ['rk_key'] | ||
rc = RClient(username, password, id_, key) | ||
result = rc.rk_create(img, code) | ||
print('验证码:', result['Result']) | ||
return result['Result'] | ||
except Exception: | ||
raise Exception('识别验证码错误') | ||
|
||
|
||
def identify_image_callback_ruokuai_search(img): | ||
return __identify_image_callback(img, 3060) | ||
|
||
|
||
def identify_image_callback_ruokuai_history(img): | ||
return __identify_image_callback(img, 3040) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
envlist = py27,py35,py36 | ||
|
||
[testenv] | ||
passenv = * | ||
deps= | ||
setuptools==34.3.1 | ||
requests | ||
|