1 #!/usr/bin/env python 2 # coding:utf-8 3 4 import requests 5 from hashlib import md5 6 7 8 class RClient(object): 9 10 def __init__(self, username, password, soft_id, soft_key): 11 self.username = username 12 self.password = md5(password.encode('utf-8')).hexdigest() 13 self.soft_id = soft_id 14 self.soft_key = soft_key 15 self.base_params = { 16 'username': self.username, 17 'password': self.password, 18 'softid': self.soft_id, 19 'softkey': self.soft_key, 20 } 21 self.headers = { 22 'Connection': 'Keep-Alive', 23 'Expect': '100-continue', 24 'User-Agent': 'ben', 25 } 26 27 def rk_create(self, im, im_type, timeout=60): 28 """ 29 im: 图片字节 30 im_type: 题目类型 31 """ 32 params = { 33 'typeid': im_type, 34 'timeout': timeout, 35 } 36 params.update(self.base_params) 37 files = {'image': ('a.jpg', im)} 38 r = requests.post('http://api.ruokuai.com/create.json', data=params, files=files, headers=self.headers) 39 return r.json() 40 41 def rk_report_error(self, im_id): 42 """ 43 im_id:报错题目的ID 44 """ 45 params = { 46 'id': im_id, 47 } 48 params.update(self.base_params) 49 r = requests.post('http://api.ruokuai.com/reporterror.json', data=params, headers=self.headers) 50 return r.json() 51 52 53 if __name__ == '__main__': 54 rc = RClient('普通用户账号', '普通用户账号密码', '软件ID', '软件key') 55 im = open('a.jpg', 'rb').read() 56 print(rc.rk_create(im, 3040)['Result'])
版权声明:
本文来源网络,所有图片文章版权属于原作者,如有侵权,联系删除。
本文网址:https://www.mushiming.com/mjsbk/1810.html