4

I am new to python and network programming and I am having trouble with a simple program. I am basically opening a connection to a nonexistent website and somehow it seems that the connection succeeds. Moreover, I get a 200 return code which means the http server has responded that it exists and the connection is OK. Here's the relevant part of my code:

import httplib

conn = httplib.HTTPConnection("Nonexistentsite.com", 80)
conn.request("GET","/")
r  = conn.getresponse()
print r.status, r.reason
conn.close()

And when I try google.com or any other existing website instead of nonexistentsite.com, I get 301 or 302 - Moved permanently.

Could you kindly clarify why this is happening, please? I am using visualStudio2010(IronPython) if that matters.

Karen Tsirunyan
  • 1,938
  • 6
  • 19
  • 30
  • Weird, in regular Python I get the proper `socket.gaierror: [Errno -2] Name or service not known`, maybe you encountered a bug? – John Doe Nov 06 '11 at 13:09
  • Unless it's an ironpython implementation problem, may I suggest the problem is somewhere else in your code. Most likely incorrectly catching the exception that is thrown over here (on regular python) from `getresponse()` when the site doesn't exist. Or have you tested with *exactly* the code above? You say it's the relevant part which implies there are other parts. – tjm Nov 06 '11 at 13:15
  • @tjm I have posted all the code. As you can see I am not handling any exceptions. Is this the expected behavior though? – Karen Tsirunyan Nov 06 '11 at 13:29
  • @Karen. Sorry, I really don't know, but I receive the error over here (the same one John Doe receives) P.S. Note, it throws in `request` not `getresponse` as I said above. – tjm Nov 06 '11 at 13:39

3 Answers3

4

You might be using an ISP that fakes DNS results in order to give you a spam page helpful search page instead of an error for nonexistant names.

What does a ping Nonexistentsite.com result in on the machine where you tested your Python code?

Baffe Boyois
  • 2,120
  • 15
  • 15
0

Running your code in Cygwin's Python, I get an error for Nonexistentsite.com, so I'm not sure if something weird is happening with IronPython.

Google.com is Moved permanently because Google has a system of redirects for their main page. For example, if they detect you are in the UK, google.com will redirect you to google.co.uk (untested, I am in the US, but that is what I have read). If I try your code with stackoverflow.com or another site that doesn't have something as complicated set up as Google, I get a 200 OK response.

davidscolgan
  • 7,508
  • 9
  • 59
  • 78
0

I tested this except I used www.google.com instead. This came up with 302 Found. After a bit of googling I found out that 302 Found means that there is a redirection. This probably means that users are redirected to the right Google site for their reigon for example www.google.co.uk for UK. The 302 - Moved Permanently is probably the same thing but it just comes up different for IronPython.

edit -

It exists because Google is still running that server and is performing redirections.