[Twisted-Python] self.channel.writeHeaders(version, code, reason, headers)\nbuiltins.AttributeError: \'NoneType\' object has no attribute \'writeHeaders\'\

Jean-Paul Calderone exarkun at twistedmatrix.com
Mon Aug 5 12:21:26 MDT 2019


On Mon, Aug 5, 2019 at 2:15 PM Waqar Khan <wk80333 at gmail.com> wrote:

> False alarm. Seems like there are some sneaky conditions when I get the
> error message.
> Like before, I use to get notifyFinish error everytime. Now, it seems that
> 6/10 times  things are "clean" but then 4/10 times there are notifyFinish
> errors.
> Wondering on your suggestion. How do I ensure whether the notifyFinish
> error deferred has been fired or not.
> Could I have like a vanilla "HelloWorld" example?
> Thanks
>
>
You can find an example of this here -
https://twistedmatrix.com/documents/current/web/howto/web-in-60/interrupted.html

Jean-Paul


> On Mon, Aug 5, 2019 at 2:24 AM Waqar Khan <wk80333 at gmail.com> wrote:
>
>> Hi Glyph,
>>     I am not sure I understand.
>>
>> Is there a method/variable in request which keeps a track whether
>> notifyFinish has been fired..
>> So, I can do something like.
>>
>> if not request.hasFiredNotifyFinish:
>>        request.finish()
>> ??
>>
>>
>> I have sort of able to get around this issue.. though I can't put a
>> finger on what actually worked.
>> Here is what I did.. First change to 19.7rc01 version.. and just fix the
>> channel issue.
>>
>> Next  self.fetch_response(request).. This is an async def.. So what I did
>> was..
>>
>> async def fetch_response(request):
>>         future = {}
>>         try:
>>            future = await some other async def.. which returns future
>>         except asyncio.CancelledError as e:
>>            print("Error..", e)
>>         return future
>>
>> I basically ended up doing this everywhere where there is async/await.
>> Next, I added this:
>> d.addErrback(lambda failure: failure.trap(asyncio.CancelledError))
>>
>>
>> So.. now.. I don't see the notifyFinish error anymore. And I am bit
>> terrified not to touch anything.. :-D
>>
>> But, I want to try out your suggestion as that seems like a more solid
>> way to handle the issue. But I am not sure I quite understand, how do I
>> figure out whether notifyFinish has been called before calling finish?
>>
>>
>> On Mon, Aug 5, 2019 at 1:56 AM Glyph <glyph at twistedmatrix.com> wrote:
>>
>>>
>>>
>>> On Aug 4, 2019, at 9:04 PM, Waqar Khan <wk80333 at gmail.com> wrote:
>>>
>>> Ah yes.. That is true..
>>>
>>> If I comment out request.finish() (Here is the doc which I tried to
>>> followed:
>>> https://twistedmatrix.com/documents/13.0.0/web/howto/web-in-60/interrupted.html
>>> )
>>> Then actually.. when I try to test out the code... (via curl or like
>>> doing requests.get .. to the URI)..
>>> it is just stuck..
>>>
>>>
>>> Yep!  This makes sense; if you don't call `.finish()` *at all* then
>>> your code will never tell the client that it's done.
>>>
>>> But if you call `.finish()` *after notifyFinish() has fired* then you
>>> get that error.
>>>
>>> If you change your code to only call `.finish()` if the deferred
>>> returned by notifyFinish() has not fired or failed yet, do you get the
>>> error?  It's possible that you still do, in which case, there's a bug in
>>> Twisted that needs to be fixed.
>>>
>>> I do want to convey my thanks for the help. Really appreciate it.
>>>
>>>
>>> Thanks for using Twisted :)
>>> -g
>>>
>>> _______________________________________________
>>> Twisted-Python mailing list
>>> Twisted-Python at twistedmatrix.com
>>> https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>>>
>> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> https://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20190805/9188f3d8/attachment-0002.html>


More information about the Twisted-Python mailing list