Closed OlofT closed 7 years ago
It's certainly possible, but it rather suggests that a deeper error is at work here. If the stream is getting closed then it shouldn't be locatable at all. Are you running this from multiple threads?
Ok! Good to know - will dig deeper.
No, it's only running from one thread.
Yeah, so from one thread that's weird.
The easiest step at first is to use pdb to catch that error and see what headers
is.
It seems to be due to the oldest stream not being finished when calling "response = connection.get_response()"
Perhaps am I misunderstanding the documentation?
I start 16 streams and then wait for all of them to return before sending again. The first time I call connection.get_response() everything is fine. Doing a simple print before: raise KeyError("Nonexistent header key: {}".format(key)) gives this for every response:
[(':status', '200'), ('apns-id', '09ecd4f4-1706-4413-ad57-cb4395cc15cb')] [('apns-id', '09ecd4f4-1706-4413-ad57-cb4395cc15cb')] [('apns-id', '09ecd4f4-1706-4413-ad57-cb4395cc15cb')]
It seems as it handles the exception if there was one status in the header. (The apps-id is added by the remote server).
The next time I call connection.get_response(), assuming it will get the response of the oldest (or any finished) stream - I only get this:
[('apns-id', '9e5f3388-7687-46d8-8115-94c1b1a8aca9')] [('apns-id', '9e5f3388-7687-46d8-8115-94c1b1a8aca9')]
And then comes the exception.
Perhaps is this due to misses of hyper? Am I supposed to always specify what request to get response from with "connection.get_response(request)" when using multiple streams?
Ah, sorry, that's almost certainly the problem. getresponse()
with no arguments really only works when you call it after each individual request. Otherwise it'll repeatedly return the same one. I think the documentation is confusing on that front. I highly recommend storing the stream IDs and using them to fetch responses.
Yes, thanks!
That was the problem, now things are working better!
And thanks for your hard work and quick replies!
No problem! We could definitely be doing better with error messages here. =)
Getting an exception when doing multiple streams, perhaps is the connection being closed and this error is just a symptom of that?
trace: response = connection.get_response() File "/usr/local/lib/python2.7/site-packages/hyper/http20/connection.py", line 312, in get_response return HTTP20Response(stream.getheaders(), stream) File "/usr/local/lib/python2.7/site-packages/hyper/http20/response.py", line 44, in init status = headers[b':status'][0] File "/usr/local/lib/python2.7/site-packages/hyper/common/headers.py", line 86, in getitem raise KeyError("Nonexistent header key: {}".format(key)) KeyError: 'Nonexistent header key: :status'