在Python中运行js报错,在js和Python中都打印过相关类型和值了,都没问题,这是怎么回事啊?
# 检查响应状态码
if response.status_code == 200:
try:
# 获取响应内容的UTF-8解码字符串
response_text = str(response.content.decode('utf-8'))
print(type(response_text))
decrypted_text = execjs.compile(open('./decrypt.js', 'r', encoding='utf-8').read()).call('decrypt',
response_text)
# 打印解密后的文本
print("Decrypted response:", decrypted_text)
except execjs.ProgramError as e:
print(f"JavaScript error: {e}")
except FileNotFoundError:
print("JavaScript file 'decrypt.js' not found.")
except UnicodeDecodeError as e:
print(f"Encoding error: {e}")
except ValueError as e:
print(f"Value error: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
else:
print(f"Failed to fetch data: {response.status_code}")
// @charset "UTF-8";
const CryptoJs = require('crypto-js');
function decrypt(t) {
// return typeof t.replace(/\s+/g, '')
// t = t.replace(/\s+/g, '')
var n = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : ""
, r = 'rewin-swhysc1234'
, i = CryptoJs.enc.Utf8.parse(r)
, o = CryptoJs.AES.decrypt(t, i, {
mode: CryptoJs.mode.ECB,
padding: CryptoJs.pad.Pkcs7
});
return CryptoJs.enc.Utf8.stringify(o).toString()
}
运行截图:
另外,注释掉的 t.replace这行没问题,可以成功执行。