twisted

Heroku and Twisted

偶尔善良 提交于 2020-01-04 23:09:49
问题 I am trying to learn Twisted, a Python framework, and I want to put a basic application online that, when it receive a message sends it back. I decided to use Heroku to host it, and I followed the instructions on their docs. import os from twisted.internet import protocol, reactor class Echo(protocol.Protocol): def dataReceived(self, data): self.transport.write(data) class EchoFactory(protocol.Factory): def buildProtocol(self, addr): return Echo() port = int(os.environ.get('PORT', 5000))

Integrating HID access with evdev on linux with Python twisted

…衆ロ難τιáo~ 提交于 2020-01-04 06:28:29
问题 On a linux machine (Debian wheezy) I am trying to write an event-based server that does the following: Grab exclusive input to the input device (a special keyboard) to prevent the keystroke get into the usual event chain. Register for events in the twisted reactor Register callback at the deferred returned from waiting for events. This callback would then send an HTTP request after a special key sequence is received. This is the sample code from the pyevdev package. It works that I get

Twisted: how to get error parameters from failure?

天涯浪子 提交于 2020-01-04 05:55:36
问题 I have a piece of code: from twisted.web.client import getPage from twisted.internet import reactor class TestError(Exception): def __init__(self, message): self.message = message def __repr__(self): return 'TestError' def gotPage(response): print response reactor.stop() def gotErr(failure): raise TestError('This is error') def newEb(failure): try: failure.raiseException() except TestError as te: print te.message reactor.stop() if __name__ == '__main__': deferred = getPage('http://somebadpage

how does a non-blocking event loop work?

∥☆過路亽.° 提交于 2020-01-04 04:08:12
问题 Twisted has a "non-blocking" event loop. I understand what a blocking event loop does (sort of, from the Wikipedia page) but can't figure out how a non-blocking one does. 回答1: while (true) wait_for_events handle_events Basically, non-blocking event loop utilizes device that allows for waiting for multiple events simultaneously ( select / poll on UNIX, WaitForMultipleEvents on Windows, epoll on Linux kqueue on FreeBSD etc). In each iteration of main loop, events (file descriptors, timers etc)

python twisted stdio example on windows doesn't work

依然范特西╮ 提交于 2020-01-03 17:08:03
问题 I started playing with python/twisted but when I test the stdin example on Windows from cmd.exe , the example doesn't work. I'm using python 2.7 and twisted 12.1.0 (binary msi package). I hoped it was a buffering problem, so I tried also running the script with "python -u stdin.y", but nothing changed. Obviously, this script works on Linux and on OS X. 回答1: There is already an open Twisted ticket to make twisted.internet.stdio work on the console in Windows. There's even a fair amount of code

python twisted stdio example on windows doesn't work

删除回忆录丶 提交于 2020-01-03 17:06:58
问题 I started playing with python/twisted but when I test the stdin example on Windows from cmd.exe , the example doesn't work. I'm using python 2.7 and twisted 12.1.0 (binary msi package). I hoped it was a buffering problem, so I tried also running the script with "python -u stdin.y", but nothing changed. Obviously, this script works on Linux and on OS X. 回答1: There is already an open Twisted ticket to make twisted.internet.stdio work on the console in Windows. There's even a fair amount of code

Use alternate authentication in twisted's Perspective Broker

主宰稳场 提交于 2020-01-03 03:40:09
问题 I am using twisted's Perspective Broker for a network application. I encountered the problem that it automatically uses an MD5 challenge-response scheme for authentication. Ideally I would prefer not to store MD5 hashes on the server-side due to a number of security vulnerabilities. Alternatively, scrypt, bcrypt or pbkdf2 provide more secure algorithms. However, while these algorithms are readily available in python, I don't quite see, whether it is possible to implement a custom

Testing with Twisted and inlineCallbacks

亡梦爱人 提交于 2020-01-02 15:02:12
问题 Here is my function definition: @defer.inlineCallbacks def get_order(order_id): # do some db operations... defer.returnValue(order_details) What I want to do is to test this function using Twisted's trial: from twisted.trial import unittest from twisted.internet import defer class OrderTest(unittest.TestCase): @defer.inlineCallbacks def test_order(self): order = yield get_order(5) raise Exception('FAIL FAIL!!') # this should fail, but never does self.assertEqual(order.id, 6) I'm very confused

'twistd' is not a recognized internal or external command

微笑、不失礼 提交于 2020-01-02 10:04:11
问题 I'm trying to develop a Twisted Web server but can't seem to run the twistd command. I've tried setting the python path and even included the path to the twistd.py script in my Path but nothing seems to work. I'm using Twisted 12.0.0 and Python 2.7 on Windows. Any help would be hugely appreciated. 回答1: You need to set the %PATHEXT% environment variable to include .py , as well as %PATH% including the path to twistd . Your most-recently-installed version of Python should then automatically

Why does scrapyd throw: “'FeedExporter' object has no attribute 'slot'” exception?

雨燕双飞 提交于 2020-01-02 06:24:18
问题 I came across a situation where my scrapy code is working fine when used from command line but when I'm using the same spider after deploying (scrapy-deploy) and scheduling with scrapyd api it throws error in "scrapy.extensions.feedexport.FeedExporter" class. one is while initializing "open_spider" signal second is while initializing "item_scraped" signal and last while "close_spider" signal 1."open_spider" signal error 2016-05-14 12:09:38 [scrapy] INFO: Spider opened 2016-05-14 12:09:38