Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8677083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:21:49+00:00 2026-06-12T20:21:49+00:00

self.agent = Agent(reactor, pool=pool) self.deferred = self.agent.request( ‘GET’, self.url, Headers({‘User-Agent’: [‘Mozilla/5.0’]}) ) self.deferred.addCallback(self.gotResponse) But

  • 0
self.agent = Agent(reactor, pool=pool)
self.deferred = self.agent.request(
            'GET',
            self.url,
            Headers({'User-Agent': ['Mozilla/5.0']})
        )

self.deferred.addCallback(self.gotResponse)

But gotResponse called for every part of received data, not for all of it. I could collect it, but how to know that i got all the data?

EDIT:

I found this (from the words “If the response body has been completely received“) but still have no idea how to implement this. I mean, what does “the failure will wrap…” mean?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:21:50+00:00Added an answer on June 12, 2026 at 8:21 pm

    The twisted documentation provides an example of how to do this.

    From http://twistedmatrix.com/documents/current/web/howto/client.html

    from pprint import pformat
    
    from twisted.internet import reactor
    from twisted.internet.defer import Deferred
    from twisted.internet.protocol import Protocol
    from twisted.web.client import Agent
    from twisted.web.http_headers import Headers
    
    class BeginningPrinter(Protocol):
        def __init__(self, finished):
            self.finished = finished
            self.remaining = 1024 * 10
    
        def dataReceived(self, bytes):
            if self.remaining:
                display = bytes[:self.remaining]
                print 'Some data received:'
                print display
                self.remaining -= len(display)
    
        def connectionLost(self, reason):
            print 'Finished receiving body:', reason.getErrorMessage()
            self.finished.callback(None)
    
    agent = Agent(reactor)
    d = agent.request(
        'GET',
        'http://example.com/',
        Headers({'User-Agent': ['Twisted Web Client Example']}),
        None)
    
    def cbRequest(response):
        print 'Response version:', response.version
        print 'Response code:', response.code
        print 'Response phrase:', response.phrase
        print 'Response headers:'
        print pformat(list(response.headers.getAllRawHeaders()))
        finished = Deferred()
        response.deliverBody(BeginningPrinter(finished))
        return finished
    d.addCallback(cbRequest)
    
    def cbShutdown(ignored):
        reactor.stop()
    d.addBoth(cbShutdown)
    
    reactor.run()
    

    The connectionLost() method of BeginningPrinter will be called when the request has completed.

    Response version: ('HTTP', 1, 0)
    Response code: 302
    Response phrase: Found
    Response headers:
    [('Location', ['http://www.iana.org/domains/example/']), ('Server', ['BigIP'])]
    Finished receiving body: Response body fully received
    

    It looks like checking if reason.check(twisted.web.client.ResponseDone) will tell you whether or not it was successful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to do the following: request = urllib2.Request(url=url, headers={ 'User-Agent' : 'Mozilla/4.0
Im parsing the source of a website and Im using this regex: /page\.php\?id\=([0-9]*)\\>(.*)\<\/a\>\<\/span\>/.match(self.agent.page.content) self.agent.page.content
I have the following code in a collection: class Author(Agent): def foo(self): self.find_another_document_and_update_it(ids) self.processed
My requirement is, When user agent change session should destroy, and it should start
What I want I want a helper app user agent (LSUIElement in Info.plist is
I have the following in tests.py. def setUp(self): self.client = Client() self.client.get('/homepage',{'join':'NPO2','siteid':1450}) self.client.session.save() self.oraganisation_list
I'm successfully making a ASIFormDataRequest using the below code. //get groups if (![self queue])
How can I change the user-agent of UIWebView in iOS 5? What I have
Agent: agent_id (primary key) User: f_id (foreign key) type I have created relation in
I'm trying to create a method that will change User-Agent for urllib2.build_opener() Thant's what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.