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
- from Crypto.Cipher import AES报错!!!PyCrypto这个库牛掰~
- 关于Python中 from Crypto.Cipher import AES这个死活报错的问题
- 解决python种输入from Crypto.Cipher import AES 报错 ImportError: No module named Crypto.Cipher
- Import Error No module named Crypto.Cipher问题解决方案
- Python报错"undefined variable from import..."
- Python报错"undefined variable from import:"
- javax.crypto.Cipher
- Android 中使用java aes加密算法,报错信息android javax.crypto.BadPaddingException: pad block corrupted解决办法
- Python 在 Eclipse报错 Undefined variable from import: setdefaultencoding
- gulp 报"import gulp from 'gulp'"的错解决方案
- from matplotlib import pyplot as plt eclipse报错
- from _curses import * ImportError: No module named '_curses' 报错
- 关于Python from VideoCapture import Device 报错的解决方法
- Crypto++学习总结---AES
- Crypto++ 入门 AES
- Crypto++学习总结---AES
- javax.crypto.Cipher 加解密
- Load Crypto.Cipher.ARC4 Failed
- JZOJsenior5477.【NOIP2017提高组】day2T2宝藏
- (10)RxJava2+Retrofit2+OkHttp3系列(综合案例)
- 关于微信投票怎么刷票数之微信投票如何快速拉票的详情
- python装饰器(decotator)详解
- HDU 2391 Filthy Rich(dp)
- from Crypto.Cipher import AES报错!!!PyCrypto这个库牛掰~
- html的table中rowspan colspan实现跨行或者跨列
- MYECLIPSE Errors running builder 'DeploymentBuilder' on project
- 类/对象大小的计算
- 二. FragmentLayout 加上 TabLayout 进行嵌套碎片 主方法内
- 【云星数据---Apache Flink实战系列(精品版)】:Apache Flink高级特性与高级应用005-Flink的作业调度情况002
- JSON 数据格式
- Python-dict和set(学习笔记2)
- 用栈求解汉诺塔问题(每日一道算法题)