471,873 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,873 software developers and data experts.

Testing for connection to a website


Okay, I already made this post, but it kinda got lost. So anyway I need to
figure out how to test if the user is able to connect to a specific website.
Last time I got pointed to the urllib2 page, but if I do urlopen() and and
am not connected, the program stops. So I don't know if that was what you
guys wanted me to do, but I don't think so, you guys are smarter than that.
So, how can I test for connection to a website.
--
View this message in context: http://www.nabble.com/Testing-for-co...p18473382.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jul 15 '08 #1
3 1992
On Jul 15, 3:43*pm, Alexnb <alexnbr...@gmail.comwrote:
Okay, I already made this post, but it kinda got lost. So anyway I need to
figure out how to test if the user is able to connect to a specific website.
Last time I got pointed to the urllib2 page, but if I do urlopen() and and
am not connected, the program stops. So I don't know if that was what you
guys wanted me to do, but I don't think so, you guys are smarter than that.
So, how can I test for connection to a website.
--
View this message in context:http://www.nabble.com/Testing-for-co...te-tp18473382p...
Sent from the Python - python-list mailing list archive at Nabble.com.
Ping it? ~_^
Jul 15 '08 #2
On 2008-07-15, Alexnb <al********@gmail.comwrote:
Okay, I already made this post, but it kinda got lost.
No, it didn't get lost. Your question was answered and you
didn't like the answer.
So anyway I need to figure out how to test if the user is able
to connect to a specific website. Last time I got pointed to
the urllib2 page, but if I do urlopen() and and am not
connected, the program stops.
How long did you wait? Depending on what/how/where the network
is broken, it make take a minute or two for the connection
attempt to fail. You may not like it, but that's how TCP
works. You're concerned with TCP connections, so you're going
to have to live with it.
So I don't know if that was what you guys wanted me to do,
Yes it was what we advised you to do.
but I don't think so, you guys are smarter than that. So, how
can I test for connection to a website.
Like we told you:

1) Open a connection using urllib or urllib2.
2) The attempt will either fail or succeed.
3) Proceed accordingly.

--
Grant Edwards grante Yow! HUGH BEAUMONT died
at in 1982!!
visi.com
Jul 15 '08 #3
Alexnb wrote:
Okay, I already made this post, but it kinda got lost. So anyway I need to
figure out how to test if the user is able to connect to a specific website.
Last time I got pointed to the urllib2 page, but if I do urlopen() and and
am not connected, the program stops. So I don't know if that was what you
guys wanted me to do, but I don't think so, you guys are smarter than that.
So, how can I test for connection to a website.
You can test DNS resolution by doing this:

import socket
#
# Check to make sure domain is legal and that I can resolve it to IP addr
#
try:
ipaddr=socket.gethostbyname(domain)
except socket.gaierror:
print "Internet connection or DNS error"

For the "connect to a specific website" portion you just have to wait until it
times out to determine failure.

-Larry
Jul 15 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Karuna | last post: by
reply views Thread by Gustavo Barbosa | last post: by
reply views Thread by Alexnb | last post: by
21 posts views Thread by =?ISO-8859-1?Q?Fad=A5?= | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.