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 3214202
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:01:58+00:00 2026-05-17T15:01:58+00:00

I am writing a test for a function that downloads the data from an

  • 0

I am writing a test for a function that downloads the data from an url with Twisted (I know about twisted.web.client.getPage, but this one adds some extra functionality). Either ways, I want to use nosetests since I am using it throughout the project and it doesn’t look appropriate to use Twisted Trial only for this particular test.
So what I am trying to do is something like:

from nose.twistedtools import deferred

@deferred()
def test_download(self):
    url = 'http://localhost:8000'

    d = getPage(url)

    def callback(data):
        assert len(data) != 0

    d.addCallback(callback)
    return d

On localhost:8000 listens a test server. The issue is I always get twisted.internet.error.DNSLookupError

DNSLookupError: DNS lookup failed: address 'localhost:8000' not found: [Errno -5] No address associated with hostname.

Is there a way I can fix this? Does anyone actually uses nose.twistedtools?

Update: A more complete traceback

Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/nose-0.11.2-py2.6.egg/nose/twistedtools.py", line 138, in errback
failure.raiseException()
File "/usr/local/lib/python2.6/dist-packages/Twisted-9.0.0-py2.6-linux-x86_64.egg/twisted/python/failure.py", line 326, in raiseException
raise self.type, self.value, self.tb
DNSLookupError: DNS lookup failed: address 'localhost:8000' not found: [Errno -5] No address associated with hostname.

Update 2

My bad, it seems in the implementation of getPage, I was doing something like:

obj = urlparse.urlparse(url)
netloc = obj.netloc

and passing netloc to the the factory when I should’ve passed netloc.split(':')[0]

  • 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-05-17T15:01:58+00:00Added an answer on May 17, 2026 at 3:01 pm

    Are you sure your getPage function is parsing the URL correctly? The error message seems to suggest that it is using the hostname and port together when doing the dns lookup.

    You say your getPage is similar to twisted.web.client.getPage, but that works fine for me when I use it in this complete script:

    #!/usr/bin/env python
    from nose.twistedtools import deferred
    from twisted.web import client
    import nose
    
    @deferred()
    def test_download():
        url = 'http://localhost:8000'
    
        d = client.getPage(url)
    
        def callback(data):
            assert len(data) != 0
    
        d.addCallback(callback)
        return d
    
    if __name__ == "__main__":
        args = ['--verbosity=2', __file__]
        nose.run(argv=args)
    

    While running a simple http server in my home directory:

    $ python -m SimpleHTTPServer
    Serving HTTP on 0.0.0.0 port 8000 ...
    

    The nose test gives the following output:

    .
    ----------------------------------------------------------------------
    Ran 1 test in 0.019s
    
    OK
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.