Closed Column01 closed 3 years ago
Hmm, this is most certainly due to me making multiple requests asynchronously.
Changing to use inline callbacks has fixed this issue.
Any tips on how I can do this async without breaking treq? I assume I need to make a client... which is what I was avoiding by using treq.
hmm. Having issues downloading a file now...
Response is: <treq.response._Response 200 'application/octet-stream' 43,626,592 bytes>
but it runs d_result.callback((filename, content))
with an empty content presumably due to an error in grabbing the content?
def jar_get(name):
d_result = defer.Deferred()
@defer.inlineCallbacks
def got_results(results):
for r in results:
if name == '-'.join(r.name_short):
resp = yield treq.get(r.url)
print(resp)
print(r.url)
filename = r.url.split('/')[-1]
content = yield resp.content()
d_result.callback((filename, content))
d_result.errback(Exception("{} is not available!".format(name)))
d = get_raw()
d.addCallbacks(got_results, d_result.errback)
return d_result
EDIT: Same error as last time, connection just gets closed.
Hmm managed to get it working. My deferrals were running their callbacks early. Think I sorted it out for now
Hey there,
I'm relatively new to Twisted's way of programming and still earning deferrals, but I've recently started to maintain some code using twisted.
I've added
treq
as a dependency and I'm in the process of updating allgetPage
requests to a proper web request usingtreq.get
but I'm now having issues where my second and all other attempts return the following error to my error handler (which just prints it out at the moment)The code that is making the requests is found here. This is called from another module where the
data
is from atreq.get().json()
deferral from here. I'm wondering, is it because I'm making the calls from inside a deferral?The run looks like the following in the console with the current print output from the code, to me, it looks like the second request for
1.17.1-snapshot
fails (which is consistent with the lack of its presence in the final output before the error.Output: