Re: [Twisted-Python] Passing additional arguments to errback
Hello, just one more question: Well, yes, you should, but still keep in mind that you can actually just pass the request like so: .addErrback(handleErrors, request) You don't really have to save the request itself anywhere as an attribute. if I understand correctly, when I put this instruction into my callback, then the errback will catch errors only from the callback, and not from agent.request, right? Such code seems hard to debug. Is this the standard procedure in Twisted to add callbacks/errbacks inside other callbacks? Best Regards Maciek ___ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Re: [Twisted-Python] Passing additional arguments to errback
Maciej Wasilak wasi...@gmail.com wrote: Hello, just one more question: Well, yes, you should, but still keep in mind that you can actually just pass the request like so: .addErrback(handleErrors, request) You don't really have to save the request itself anywhere as an attribute. if I understand correctly, when I put this instruction into my callback, then the errback will catch errors only from the callback, and not from agent.request, right? Such code seems hard to debug. Is this the standard procedure in Twisted to add callbacks/errbacks inside other callbacks? Best Regards Maciek ___ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python No it'll catch errors from anything previous in the chain - either the agent call or the callback. If you read the docs carefully this should be clear. -- Sent from my phone with, please excuse brevity and typos___ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Re: [Twisted-Python] Passing additional arguments to errback
Laurens, You don't have to do it from in there. You can do .addErrback(handleErrors, request), since it's all the same request object, right? Aaargh! I see the problem now. I wrote everything as part of the Protocol class (DD - DeferredsDictionaries), when I should have extracted request functionality into separate class. Then I can save request body as a class member between callback and errback. Thanks!!! 1. It seems self.endpoint is a t.w.s.Site object. That's kind of confusing, since twisted has an endpoint concept that's one step removed from a Site (endpoints connect or listen with factories, a Site is a factory). You might want to reconsider that name :) Endpoint is the official name in draft: http://tools.ietf.org/html/draft-ietf-core-coap-18 I'll rename it to coap_endpoint to avoid confusion 2. It's kind of strange to start with defer.succeed() and then start making a callback chain IMHO, but it's not wrong, really. I've recently understood callback chaining and I really like the idea. I guess it's this old proverb about having a hammer, and seeing nails everywhere. I'll try to come up with something better :) . Case closed - thank you very much! Regards Maciek ___ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Re: [Twisted-Python] Passing additional arguments to errback
On Thu, Sep 5, 2013 at 12:00 PM, Maciej Wasilak wasi...@gmail.com wrote: Laurens, You don't have to do it from in there. You can do .addErrback(handleErrors, request), since it's all the same request object, right? Aaargh! I see the problem now. I wrote everything as part of the Protocol class (DD - DeferredsDictionaries), when I should have extracted request functionality into separate class. Then I can save request body as a class member between callback and errback. Thanks!!! Well, yes, you should, but still keep in mind that you can actually just pass the request like so: .addErrback(handleErrors, request) You don't really have to save the request itself anywhere as an attribute. 1. It seems self.endpoint is a t.w.s.Site object. That's kind of confusing, since twisted has an endpoint concept that's one step removed from a Site (endpoints connect or listen with factories, a Site is a factory). You might want to reconsider that name :) Endpoint is the official name in draft: http://tools.ietf.org/html/draft-ietf-core-coap-18 I'll rename it to coap_endpoint to avoid confusion 2. It's kind of strange to start with defer.succeed() and then start making a callback chain IMHO, but it's not wrong, really. I've recently understood callback chaining and I really like the idea. I guess it's this old proverb about having a hammer, and seeing nails everywhere. I'll try to come up with something better :) . No problem. Case closed - thank you very much! Glad to have helped. Regards Maciek cheers lvh ___ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
Re: [Twisted-Python] Passing additional arguments to errback
Cześć Maciek :) In general, you can pass extra arguments when you call addCallback(s) or addErrback. They will get passed to the callback. However, as a side note to that code example, do you understand the difference between .addCallbacks(cb, eb) and: .addCallback(cb).addErrback(eb) and: .addErrback(eb).addCallback(cb) ... Also, keep in mind that you only errback when there is an issue setting up the connection. If the server successfully responds with an error (say, a 404 Not Found, or something), the callback will be called with the response object. So, your question doesn't make a lot of sense to me: if the errback gets called, there's not really a response! Also, if you want to do scraping with Twisted, consider looking at Scrapy, a fully-featured web scraper that uses Twisted internally. pozdrawiam lvh ___ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python