from Crypto.Cipher import AES报错!!!PyCrypto这个库牛掰~

来源:互联网 发布:手机淘宝中评改好评 编辑:程序博客网 时间:2024/06/01 22:01

from Crypto.Cipher import AES报错:

用了一天时间处理这个报错,然后各种捯饬,始终不行,后来在github上把源码下载放在LIB文件夹下,还是不行,在stackoverflow搜索时看见一句话说,报错的类名属于Linux,然后在Linux跑了下脚本,好了!!!喜极而泣~

直接pip install pycryto,脚本就能跑起来了~

送你们个好东西:

# -*- coding:utf8 -*-import base64import codecsimport jsonimport requestsfrom Crypto.Cipher import AES# 返回搜索列表的paramsdef get_music_list(keyword):    first_param = '{"hlpretag":"","hlposttag":"","id":"","s":"' + keyword + '","type":"1","offset":"0","total":"true","limit":"100","csrf_token":""}'    return get_params(first_param)# 返回每个歌曲的paramsdef get_music_url(id):    first_param = '{ids: "[' + str(id) + ']", br: 128000, csrf_token: ""}'    return get_params(first_param)# 返回加密后的POST参数paramsdef get_params(first_param):    iv = '0102030405060708'    first_key = '0CoJUm6Qyw8W8jud'    second_key = 16 * 'F'    h_encText = AES_encrypt(first_param, first_key, iv)    h_encText = AES_encrypt(h_encText, second_key, iv)    return h_encText# 返回加密后的POST参数encSecKeydef get_encSecKey():    # encSecKey是固定的参数    encSecKey = '257348aecb5e556c066de214e531faadd1c55d814f9be95fd06d6bff9f4c7a41f831f6394d5a3fd2e3881736d94a02ca919d952872e7d0a50ebfa1769a7a62d512f5f1ca21aec60bc3819a9c3ffca5eca9a0dba6d6f7249b06f5965ecfff3695b54e1c28f3f624750ed39e7de08fc8493242e26dbc4484a01c76f739e135637c'    return encSecKey# AES加密算法def AES_encrypt(text, key, iv):    pad = 16 - len(text) % 16    text = text + pad * chr(pad)    encryptor = AES.new(key, AES.MODE_CBC, iv)    encrypt_text = encryptor.encrypt(text)    encrypt_text = base64.b64encode(encrypt_text)    return encrypt_text# 返回json数据def get_json(url, params, encSecKey):    data = {        "params": params,        "encSecKey": encSecKey    }    response = requests.post(url, data=data)    return response.contentif __name__ == "__main__":    search_url = 'http://music.163.com/weapi/cloudsearch/get/web?csrf_token='    url = 'http://music.163.com/weapi/song/enhance/player/url?csrf_token='    singer_name = raw_input('请输入歌手名:')    params = get_music_list(singer_name)    encSecKey = get_encSecKey()    json_text = get_json(search_url, params, encSecKey)    json_dict = json.loads(json_text)    for item in json_dict['result']['songs']:        p = get_music_url(item['id'])        music = get_json(url, p, encSecKey)        songs = u'歌名:' + item['name'] + u'歌手:' + item['ar'][0]['name'] + '\n' + json.loads(music)['data'][0]['url']        with codecs.open(singer_name + '.txt', 'a', encoding='utf-8') as f:            f.write(songs + '\n')
阅读全文
0 0
原创粉丝点击