Tag: python

错误:ImportError:没有名为docx的模块 – >使用nodeJS python-shell包来控制python脚本

我正在尝试一些相对简单但是出现这个错误: Error: ImportError: No module named docx 这是我的nodeJS脚本: const python = require('python-shell'); const shell = new python('../Python/test.py'); let names = ['Hubert', 'Rupert', 'Sherbert', 'Wubbert', 'Paul']; shell.send(JSON.stringify(names)); shell.on('message', message => console.log(message)); shell.end(message => {console.log(message)}); python脚本“test.py”: import sys, json from docx import Document names = json.loads(sys.stdin.readlines()[0]) document = Document('test.docx') for name in names: for paragraph in document.paragraphs: […]

使用Node.js AES点击encryption并使用PyCrypto进行解密

好吧,所以基本上我有问题与Python解密。 我设法使用Node.jsencryption/解密数据 – 使用“aes-128-ctr”,PyCrypto也是如此,但是当我尝试使用Node.js进行encryption并使用Python进行解密时,我得到的解密文本无效。 Node.js代码: var key = "1234567890123456"; var cipher = crypto.createCipher("aes-128-ctr",key) var ctext = cipher.update('asasasa','utf8','hex') + cipher.final('hex') console.log(ctext) // outputs: "f2cf6ecd8f" Python代码: counter = Counter.new(128) cipher = AES.new("1234567890123456", AES.MODE_CTR, counter=counter) cipher.decrypt("f2cf6ecd8f") // outputs: weird encoding characters 顺便说一下,我并不在乎这种encryption的安全级别,我更关心性能。

python(pycrypto)和nodejs(crypto)之间不匹配的encryption(aes-128-cbc)

我有这个python代码,我需要翻译成nodejs。 python代码使用来自encryption的pycrypto。 在nodejs方面,我正在使用本地encryption模块。 encryption的string似乎不匹配。 from Crypto.Cipher import AES from binascii import b2a_hex, a2b_hex import json raw_key = [0x58, 0x86, 0x17, 0x6d, 0x88, 0x7c, 0x9a, 0xa0, 0x61, 0x1b, 0xbb, 0x3e, 0x20, 0x28, 0xa4, 0x5a] key = str(bytearray(raw_key)) raw_iv = [0x34, 0x2e, 0x17, 0x99, 0x6d, 0x19, 0x3d, 0x28, 0xdd, 0xb3, 0xa2, 0x69, 0x5a, 0x2e, 0x6f, 0x1b] iv […]

消息未定义,主题成为缓冲区(ZMQ)

我想使用ZeroMQ进行发布和订阅。 我使用python作为发布者和节点js作为订阅者。 这里是代码: pub.py import zmq import random import sys import time port = "3001" if len(sys.argv) > 1: port = sys.argv[1] int(port) context = zmq.Context() socket = context.socket(zmq.PUB) socket.bind("tcp://127.0.0.1:3001") while True: topic = "hello" messagedata = "world" print "%s %s" % (topic, messagedata) socket.send("%s %s" % (topic, messagedata)) time.sleep(1) sub.js var zmq = require […]

我怎样才能改变PhantomJS的屏幕分辨率?

无论如何,我无法find关于屏幕制裁改变的问题。 总是会有1024×768 。 更改viewportSize本身不会改变屏幕分辨率。 我检查了这里的决议: 链接 这是为节点: var WebPage = require('webpage'); page = WebPage.create() page.onInitialized = function () { page.evaluate(function () { window.screen = {width: 1600, height: 900, availWidth: 1600, availHeight: 900}; }); }; page.open('http://browserspy.dk/screen.php'); page.onLoadFinished = function () { page.render('ScreenShot' + '.png'); phantom.exit(); } 任何人都可以重新为Python?

在javascript中从promt.get中修剪换行符

所以我在一个控制台(raspbian lite是确切的,但我认为这应该不重要)。 我要求我的js程序的用户提供一些数据(姓名,出生date等)。 这些数据被传送到一个python程序。 问题:一旦在Python中,我的variables的值的末尾粘贴换行符。 我可以修剪它在python中,但我更喜欢在JavaScript的早期做。 这是我的代码:正如你可以看到我已经尝试更换换行符,这是行不通的。 prompt.get(['name', 'date_start', 'date_end'], function (err, result) { if (err) { return onErr(err); }; console.log('Command-line input received:'); console.log(' Name ' + result.name); console.log(' Start date: ' + result.date_start); console.log(' End date: ' + result.date_end); var PythonShell = require('python-shell'); var pyshell = new PythonShell('new_try_crypto.py'); pyshell.send(result.name.replace('\n', '')); pyshell.send(result.date_start.replace('\n', '')) pyshell.send(result.date_end.replace('\n', ''))

使用python-shell将TypedArray数据从NodeJS发送到Python的最佳方法

我试图从NodeJS发送数据使用python-shell在Python中进行处理。 我的Python脚本需要一个float32数组,但我不知道如何使用python-shell发送该数据types。 我可以发送一个string没有问题,我知道我的Python脚本工作正常否则。 有没有办法直接发送数组或我需要做一些数据转换或parsing在Python? 这是我现在正在尝试的: 在Python中: import sys input = sys.stdin.read() print type(input) 在节点中: var PythonShell = require('python-shell'); var pyshell = new PythonShell('script.py', {mode:'binary'}); // data is float32 TypedArray pyshell.send(data).end(function(err){ if (err){console.log(err, 'did not work')}; }); pyshell.on('message', function (message) { console.log('message received', message); }); 在这里我得到以下错误: net.js:655 throw new TypeError( ^ TypeError: Invalid data, chunk must […]

使用C ++中的数组调用一个带有可变数量参数的函数(如python的*运算符)

我想用C ++编写一个v8模块; 在那里,函数在数组中接收可变数目的参数。 我想采取该数组,并调用一个函数,如gettext和printf接收格式化的string,这是必要的参数。 问题是,如何获取一个数组并将这些元素作为参数发送给其中一个函数呢? 在Python中,我会做这样的事情: def the_function(s, who, hmany): print s%(who, hmany) the_args = ["Hello, %s from the %d of us", "world", 3] the_function(*the_args) 如何在C ++中完成? (我正在使用v8和node.js,所以也许有一个函数或类在我不知道的这些名称空间的某处)

在JavaScript中与Python的chr()相对应

JavaScript方法String.fromCharCode()行为等同于Python的unichar() ,其含义如下: print unichr(213) # prints Õ on the console console.log(String.fromCharCode(213)); // prints Õ on the console as well 但是,为了我的目的,我需要一个与Python函数chr()相当的JavaScript。 有没有这样的JavaScript函数或方式使String.fromCharCode()行为像chr() ? 也就是说,我需要一些模仿JavaScript的东西 print chr(213) # prints on the console

与Node.js服务器应用程序通信

我正在构build一个聊天应用程序,该应用程序由一个带有Node.js / socket.io驱动的聊天服务器的Django Web后端组成。 有些情况下,通过Web界面(例如禁止用户)进行的更改需要立即推送到聊天服务器。 我可以想到以下选项: 使用基于Python的socket.io客户端与服务器直接连接(有哪些好的Python客户端?) 使用redis或消息队列做pub / sub的事件(似乎是矫枉过正) 在辅助localhost-only端口上实现一个简单的TCP协议(这可以使用内置的Node和Python TCP库来完成) 什么是最好的select?