from Crypto.Cipher import AES报错!!!PyCrypto这个库牛掰~
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash
·
from Crypto.Cipher import AES报错:
用了一天时间处理这个报错,然后各种捯饬,始终不行,后来在github上把源码下载放在LIB文件夹下,还是不行,在stackoverflow搜索时看见一句话说,报错的类名属于Linux,然后在Linux跑了下脚本,好了!!!喜极而泣~
直接pip install pycryto,脚本就能跑起来了~
送你们个好东西:
# -*- coding:utf8 -*-
import base64
import codecs
import json
import requests
from Crypto.Cipher import AES
# 返回搜索列表的params
def 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)
# 返回每个歌曲的params
def get_music_url(id):
first_param = '{ids: "[' + str(id) + ']", br: 128000, csrf_token: ""}'
return get_params(first_param)
# 返回加密后的POST参数params
def 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参数encSecKey
def 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.content
if __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')
A beautiful web dashboard for Linux
最近提交(Master分支:4 个月前 )
186a802e
added ecosystem file for PM2 5 年前
5def40a3
Add host customization support for the NodeJS version 5 年前
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐


所有评论(0)