twisted

What is the practical difference between xml, json, rss and atom when interfacing with Twitter?

喜你入骨 提交于 2019-12-04 22:56:59
问题 I'm new to web services and as an introduction I'm playing around with the Twitter API using the Twisted framework in python. I've read up on the different formats they offer, but it's still not clear to me which one I should use in my fairly simple project. Specifically the practical difference between using JSON or XML is something I'd like guidance on. All I'm doing is requesting the public timeline and caching it locally. Thanks. 回答1: For me it boils down to convenience. Using XML, I have

How to declare ports in Cloud9 using Python

こ雲淡風輕ζ 提交于 2019-12-04 22:15:19
问题 I'm new to using Cloud9 IDE (c9) and so far it looks great, except a few minor things. I see from the docs that to start up a simple node.js http server, you have to pass in process.env.PORT in place of the regular port such as "8080". Node Hello World example: var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(process.env.PORT, process.env.IP); What I want to know is, on c9, can you only

Async query database for keys to use in multiple requests

这一生的挚爱 提交于 2019-12-04 21:53:00
I want to asynchronously query a database for keys, then make requests to several urls for each key. I have a function that returns a Deferred from the database whose value is the key for several requests. Ideally, I would call this function and return a generator of Deferreds from start_requests . @inlineCallbacks def get_request_deferred(self): d = yield engine.execute(select([table])) # async d.addCallback(make_url) d.addCallback(Request) return d def start_requests(self): ???? But attempting this in several ways raises builtins.AttributeError: 'Deferred' object has no attribute 'dont

Twisted, MySQLdb and (2006, 'MySQL server has gone away') using Twisted adbapi

隐身守侯 提交于 2019-12-04 16:46:32
In twisted I am a perpetual event loop that is always lookig for a new query to run It polls a SQS queue and are are times where time between queres is long enough to time out and this is the error I get when a new query arrives... MySQLdb _mysql_exceptions.OperationalError: (2006, 'MySQL server has gone away') here is my connection self.pool = adbapi.ConnectionPool("MySQLdb", self.parms['host'], self.parms['username'], self.parms['password'], self.parms['database']) Here is the logic I use to try and solve the problem. try: d = self.pool.runQuery(query, ()) except: self.pool = adbapi

Twisted Python + spawnProcess. Getting output from a command

╄→尐↘猪︶ㄣ 提交于 2019-12-04 14:44:31
问题 I'm working to wrap the Minecraft server application with a Twisted Python server that has a RESTful API for getting the list of currently connected players. The Twisted app starts the minecraft server via reactor.spawnProcess(), then communicates via a ProcessTransport, which writes to stdin. Reading stdout and stdin is handled by a separate protocol.ProcessProtocol class. Given that I want to get the results of a very specific command (the 'list' command, which returns something like this:

Benefits of twisted-suds - Async way of using python suds soap lib

匆匆过客 提交于 2019-12-04 14:26:09
问题 I'm using python suds library to make a SOAP client based on a local wsdl file. My goal is to use Twisted as the backend so I query the SOAP servers in a asyncronous way. I know this topic has been covered different times (here1, here2), but I still have some questions. I've seen three different approaches to use twisted with suds: a) Applying this patch to the suds library. b) Use twisted-suds, which is a fork of suds. c) Influenced by this post, I implemented Client_Async suds client using

Can twisted be implemented in Java?

风流意气都作罢 提交于 2019-12-04 13:37:40
I remember reading that the following features lead to the development of interesting frameworks/libraries in Python:- (I read the article from http://www.python.org/workshops/2002-02/papers/09/index.htm ) A simple class model, which facilitates inheritance. Dynamic typing, which means that the code needs to assume less. Built-in memory management. Java is statically compiled, and it has a garbage collector too. I wonder if its class model can be termed simple, however, keeping in mind the above mentioned points I have the following doubts:- Does Java has a Twisted analogue in Python(which is

How to unit test code that makes HTTP requests with twisted.web.client.Agent?

帅比萌擦擦* 提交于 2019-12-04 13:27:44
I'm looking for hints or examples that illustrate how to unit test code that makes HTTP requests using twisted.web.client.Agent. Is it possible to use the real Agent in tests and configure it to connect to a fake HTTP server using StringTransport (no real TCP connetion)? Or is it better to mock out the Agent and inject a mock into classes that use the Agent? it is certainly possible to use a real Agent . You must construct the Agent instance with a reactor as first argument; as such, you can provide a fake reactor, such as MemoryReactor . Although that's a pretty handy way to get down in the

How to use threading in Scrapy/Twisted, i.e. how to do async calls to blocking code in response callbacks?

左心房为你撑大大i 提交于 2019-12-04 13:09:20
I need run some multi-thread\multiprocessing work (because I have some library which uses blocking call) in Scrapy, and after its completion put back Request to Scrapy engine. I need something like this: def blocking_call(self, html): # .... # do some work in blocking call return Request(url) def parse(self, response): return self.blocking_call(response.body) How I can do that? I think I should to use Twisted reactor and Deferred object. But Scrapy parse callback must return only None or Request or BaseItem object. If you want to return a Deferred that fires after your blocking operation has

Managing multiple Twisted client connections

眉间皱痕 提交于 2019-12-04 12:18:07
问题 I'm trying to use Twisted in a sort of spidering program that manages multiple client connections. I'd like to maintain of a pool of about 5 clients working at one time. The functionality of each client is to connect to a specified IRC server that it gets from a list, enter a specific channel, and then save the list of the users in that channel to a database. The problem I'm having is more architectural than anything. I'm fairly new to Twisted and I don't know what options are available for