Tag: python

将Node.js脚本移植到Python

我想移植这个Node.js脚本来控制一个Sky框到Python, https://github.com/dalhundal/sky-remote/blob/master/sky-remote.js 我已经完成了,做了最好的,我可以做的,代码是在下面; import time, math, socket, struct, time from array import array #sky q port 5900 class remote: commands={"power": 0, "select": 1, "backup": 2, "dismiss": 2, "channelup": 6, "channeldown": 7, "interactive": 8, "sidebar": 8, "help": 9, "services": 10, "search": 10, "tvguide": 11, "home": 11, "i": 14, "text": 15, "up": 16, "down": 17, "left": 18, […]

节点:等待python脚本运行

我有以下代码。 我在哪里上传文件,然后我读取文件和console输出console.log(obj) 。 但是回应是第一位的,Python脚本在幕后运行。 我如何使代码等待python脚本运行,然后继续? router.post(`${basePath}/file`, (req, res) => { //Upload file first PythonShell.run('calculations.py', { scriptPath: '/Path/to/python/script' }, function (err) { console.log(err); let obj = fs.readFileSync('Path/to/file', 'utf8'); console.log(obj); }); return res.status(200).send({ message : 'Success', }); }); 我不能得到console.log(obj); 输出,因为它在响应之后运行。 我怎样才能让它等待python脚本运行并获得console.log(obj)输出。

在Python中是否有NODE_ENV等价物

在Python中是否有NODE_ENV等价物? 我想根据执行环境dynamic地将JSONconfiguration加载到python应用程序中。 在nodeJs中,我通过使用process.env.NODE_ENV来做到这一点。 例如, 我开始这样的应用程序, NODE_ENV=production node server.js 并且像这样在应用程序中使用variables, if(process.env.NODE_ENV == "production") { // Load the production config file here (eg: database.json) } else { // Load the development config file here (located in a different directory) } 我怎样才能在Python中实现相同? 或者我可以使用python virtualenv或python setuptools有一个解决方法?

节点js中的JSON错误未定义为发布数据的前缀

我无法发布json到一个小的node.js http服务器。 邮政数据总是在它的前面似乎有一个“未定义的”。 我可能做的很蠢,所以我的道歉! 我启动服务器,并用下面的py脚本发布一些json: >>node simplehttp.js >>python post.py '{"foo":"bar"}' 服务器得到这个 >>Request received: undefined{"foo": "bar"} Invalid JSON:undefined{"foo": "bar"} 节点http服务器 var http = require("http"); // http-server var server_http = http.createServer( // Function to handle http:post requests, need two parts to it // http://jnjnjn.com/113/node-js-for-noobs-grabbing-post-content/ function onRequest(request, response) { request.setEncoding("utf8"); request.addListener("data", function(chunk) { request.content += chunk; }); request.addListener("end", […]

Nodejsencryption与Python hashlib

我试图做一个Python函数和nodejs函数计算相同的散列。 但是,好像输出的二进制文件在nodejsencryption和python hashlib之间是不同的。 我正在使用的python是: hash = hashlib.sha512() hash.update(salt) hash.update(password.encode('utf8')) hash.digest() 节点/咖啡文本是: crypto.createHash('sha512').update(salt, 'binary').update(password, 'utf8').digest() 这些线应该产生相同的结果,但由于某些原因,他们不。 帮帮我?

请求库不正确地通过代理来引导HTTP请求

我知道如何使用requests ,但由于某种原因,我没有成功地让代理工作。 我正在提出以下要求: r = requests.get('http://whatismyip.com', proxies={'http': 'http://148.236.5.92:8080'}) 我得到以下内容: requests.exceptions.ConnectionError: [Errno 10060] A connection attempt failed b ecause the connected party did not properly respond after a period of time, or e stablished connection failed because connected host has failed to respond 然而,我知道代理工程,因为使用节点: request.get({uri: 'http://www.whatismyip.com', proxy: 'http://148.236.5.92:8080'}, function (err, response, body) {var $ = cheerio.load(body); […]

Python的TCP套接字客户端

我需要有一个TCP套接字客户端连接到服务器发送数据和接收。 但是,这个套接字必须一直打开,我不能打开另一个套接字。 我总是有一些数据要发送,然后处理以前发送的数据的答案。 如果我可以打开多个套接字,我认为它更容易。 但在我的情况下,我必须发送一切在同一个套接字asynchronous。 所以问题是,你推荐在Python生态系统中使用什么? (扭曲,龙卷风等)我应该考虑Node.js或另一种select?

Python可以写入数据库,而Meteor可以被动更新

Python可以将数据写入数据库(mongdb),并让Meteor接收数据库写入更新并更新前端?

如何从程序自动生成一个铬扩展程序?

我正在开发一个Chrome扩展,我不知道有什么办法可以将开发目录压缩成.crx文件,可以像使用Python或NodeJS一样通过程序在Chrome中安装? 我发现这个链接说你可以将.crx改成.zip ,解压后你可以看到扩展的代码。 所以,我反过来试了一下。 我手动将我的开发chrome扩展目录压缩为.zip文件格式,并将.zip更改为.crx ,然后尝试将它安装在chrome中,但它不起作用。 很显然,使用程序压缩目录到.zip将其重命名为.crx不起作用。 如何从程序自动生成一个铬扩展程序? 我正在使用Python和NodeJS。

使用节点芹菜(MeteorJS)和ampq后端时,Celery不会返回结果

我刚开始使用Celery,一个芹菜工作人员用Python编写,并且使用node-celery从node / Meteor发送任务。 为什么没有从client.call()返回result ? Python工作控制台显示任务已经发送并成功处理。 但没有任何事情ready ,似乎正在开火! 使用Celery 3.1.7,RabbitMQ 3.2.2,node-celery 0.1.1,Meteor 0.7.0.1 节点 var celery = Meteor.require('node-celery'), client = celery.createClient({ CELERY_BROKER_URL: 'amqp://guest:guest@localhost:5672//', CELERY_RESULT_BACKEND: 'amqp://', CELERY_TASK_SERIALIZER: 'json', CELERY_RESULT_SERIALIZER: 'json' }); client.on('error', function(err) { console.log(err); }); client.on('connect', function() { console.log('Connected') var results = client.call('tasks.echo', ['Hello world'], function(result) { console.log('results:' + result); }); results.on('pending', function(result) { console.log('pending: […]