#!/usr/bin/python
# -*- coding: UTF-8 -*-
from hashlib import md5
import requests
image_path = 'image.png' # 存放验证码图片地址
url = 'http://www.seemmark.com/external-api/external/captcha/v3'
key = '58f0a437e7798958a686bb33' # 用户专属key
def signature(args, key):
message = '&'.join(['='.join(item) for item in sorted(args.items())])
message = '&'.join([message, key])
return md5(message.encode('utf-8')).hexdigest()
def do_test(user_id):
data = {
'codeID': '1001adf11eefe',
'userId': user_id,
}
image_file = open(image_path, 'rb')
data['image'] = image_file.read().encode('base64') #读取图片用base64进行编码
data['sign'] = signature(data, key)
print data
resp = requests.post(url, data=data)
print resp.content
image_file.close()
if __name__ == '__main__':
image = open('image.png','rb')
message = image.read()
print message
print len(message)
message = image.read().encode('base64')
# print message
# print len(message)
do_test('1234')
网友评论