Tag: python

将python哈希摘要移植到节点js

我试图将一个Python脚本移植到Node,而且我已经陷入了SHA1哈希。 以下Python代码: import hashlib user = 'test' ret = hashlib.sha1(user.encode('utf-8')).digest() print(ret); 打印出来: b'\xa9J\x8f\xe5\xcc\xb1\x9b\xa6\x1cL\x08s\xd3\x91\xe9\x87\x98/\xbb\xd3' 在Node中我需要这种格式的SHA1哈希。 这个Javascript: var crypto = require('crypto'); var generator = crypto.createHash('sha1'); generator.update(new Buffer('test')); console.log(generator.digest('binary')); 版画 ©Jå̱sÓé/»Ó 我如何让Node以与Python相同的风格产生输出? 这显然不是二进制或hex,python输出格式是什么?

铸造到数组失败与moongoose和字典

我有一个问题,在MongoDB中插入数据与mongoose 这是我的db.js模型: var Appointment = new Schema({ date: Date, coach: ObjectId, complement: String, isOwner: Boolean, fiter : ObjectId, fiters: [ { user: ObjectId, isOwner: Boolean, status: String, invitationDate: Date } ], place: ObjectId, objectif : ObjectId, pricing: Number, status: String, ratings: [ { date: Date, user: ObjectId, score: Number, comment: String, target: ObjectId, targetType: String […]

如何使节点js连接到python?

我是新来的节点js和python只是我想通信节点js到python,反之亦然。 我需要一个简单的脚本来运行并在Web浏览器上托pipe节点js中执行python脚本。 只需要运行带有托pipe环境的节点js脚本,就可以将一个消息从节点js传输到python。

将Nodejs签名散列函数转换为Python

我试图连接到只有Nodejs文档的API,但是我需要使用Python。 官方文档声明hhtp请求需要像这样签名,只给出这个代码: var pk = "…. your private key …."; var data = JSON.strigify( {some JSON object} ); var signature = crypto.createSign('RSA-SHA256').update(data).sign(pk, 'base64'); 到目前为止,我被封锁在那里: from Crypto.PublicKey import RSA from Crypto.Signature import PKCS1_v1_5 from Crypto.Hash import SHA256 import base64 private_key_loc='D:\\api_key' BODY={ some JSON } data=json.dumps(BODY) def sign_data(private_key_loc, data): key = open(private_key_loc, "r").read() rsakey = RSA.importKey(key,passphrase='c9dweQ393Ftg') signer […]

从标准input读取时,Node.js无法读取pythonsubprocess标准输出

我有一个node.js脚本启动一个pythonsubprocess并读取它的stdout。 只要Python进程不尝试从标准input读取,它就会工作。 然后父进程没有从孩子得到任何东西。 我在这里有node.js脚本和两个pythontesting用例:(这两个示例工作,如果你评论尝试从标准input读取的行) 第一个孩子: import sys print('before') for line in sys.stdin: print(line) print('after') 第二个孩子: import sys print('before') while True: line = sys.stdin.readline() if line != '': print(line) else: break print('after') 家长: const spawn = require('child_process').spawn; let client = spawn('python', ['test1.py'], {cwd: '/tmp'}); client.stdout.on('data', (data) => { console.log(data.toString()); }); client.stderr.on('data', (data) => { console.log(data.toString()); }); […]

使用scrapy python抓取NodeJs和AngularJs网站

我正在尝试使用scrapy python抓取网站,大部分网站已经成功完成,但是大多数网站都给出了难度,因为它们运行在Nodejs和angularjs框架或其他java框架上,scrapy抓取工具无法从网页中获取详细信息。 请在这里我需要你的关注。 期待你的最早的帮助。 在这里你可以find最初我用于testing基地的代码。 import scrapy from selenium import webdriver from scrapy.http import TextResponse class QuotesSpider(scrapy.Spider): name = "quotes" start_urls = ['https://en-ae.wadi.com/home_entertainment-televisions/?ref=navigation'] def parse(self, response): self.log('i have just visited the ' + response.url) yield{ 'product_name' : response.css('p.description.ng-binding > span::text').extract_first(), } 提前致谢。

通过nodejs执行python脚本

我试图执行这段执行python脚本的节点js代码。 通过这个代码工作正常。 但是立即在前端显示“运行”和“结束”的响应。 一旦python脚本的执行完成,就必须显示“finshed”。 app.post('/execute', function(request, response){ response.write("running"); console.log("executing") var pyshell = new PythonShell('./python_codes/test.py') pyshell.on('message', function (message) {console.log(message);}); pyshell.end(function (err) {if (err){throw err;};console.log('finished');}); response.write("finished"); response.end(); });

节点和python之间的通信

我有一个节点脚本: //start.js var spawn = require('child_process').spawn, py = spawn('python', ['compute_input.py']), data = [1,2,3,4,5,6,7,8,9], dataString = ''; py.stdout.on('data', function(data){ dataString += data.toString(); }); py.stdout.on('end', function(){ console.log('Sum of numbers=',dataString); }); py.stdin.write(JSON.stringify(data)); py.stdin.end(); 和一个python脚本: ## compute_input.py import sys, json, numpy as np #Read data from stdin def read_in(): lines = sys.stdin.readlines() #Since our input would only be having […]

如何部署在heroku上使用python脚本的nodejs应用程序

我有一个基本的nodejs应用程序可以在heroku上正常工作,但是我想添加一个nodejs将调用的使用numpy包的python脚本。 我已经得到它在我的本地主机工作,但我努力让它在heroku上工作,因为它不承认numpy包,我似乎无法安装与PIP,因为它不能被识别。

JS与Python的字节数组编码

我试图将字节数组转换为string,然后通过套接字发送到远程服务器。 我已经成功地在Python原型的代码,并试图将其迁移到Javascript 。 由于某种原因,这两种语言之间的最后一个字符有差异。 Python代码 def make_checksum(data): num = 0x00 for num2 in data: num = (num + num2) & 0xFF return num data = [0x56, 0x54, 0x55, 0x3E, 0x28, 0x00, 0x08, 0x00, 0x03, 0x01, 0x46, 0x00, 0x00, 0x00, 0xC0] message = bytearray(data + [make_checksum(data)]) 使用Javascript function checksum(data) { let res = 0x00 for (let […]