Why can my program connect to a non-existent website?

I am new to python and network programming and am having problems with a simple program. I basically open a connection to a non-existent website, and for some reason it seems that the connection is succeeding. Moreover, I get a return code of 200, which means that the HTTP server replied that it exists, and the connection is OK. Here is 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 to use google.com or any other existing website instead of nonexistentsite.com , I get 301 or 302 - Moved permanently .

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

+4
source share
3 answers

You can use an ISP that fakes DNS results in order to give you <spam> Spamudar> a useful search page instead of an error for nonexistant names.

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

+4
source

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

Google.com Moved permanently because Google has a home page redirect system. For example, if they find that you are in the UK, google.com redirect you to google.co.uk (unverified, I am in the USA, but this is what I read). If I try your code with stackoverflow.com or another site that does not have something complicated configured like Google, I get a 200 OK response.

0
source

I tested this, except that I used www.google.com instead. This caused 302 found. After several searches, I found that 302 Found means that there is a redirect. This probably means that users are redirected to the correct Google site for their re-fly, for example www.google.co.uk for the UK. 302 - Moved forever - it's probably the same thing, but for IronPython it is just different.

edit -

It exists since Google is still running on this server and is redirecting.

0
source

Source: https://habr.com/ru/post/1379862/


All Articles