Re: URLError:

2022-02-12 Thread Gisle Vanem

Shaozhong SHI wrote:


The following is used in a loop to get response code for each url.

print (urllib.request.urlopen(url).getcode())

However, error message says: URLError: 

11001 == WSAHOST_NOT_FOUND.

Look in any 'winsock.h' header:
  #define WSAHOST_NOT_FOUND (WSABASEERR+1001)

--
--gv
--
https://mail.python.org/mailman/listinfo/python-list


Re: URLError:

2022-02-12 Thread Chris Angelico
On Sun, 13 Feb 2022 at 07:17, Shaozhong SHI  wrote:
>
> The following is used in a loop to get response code for each url.
>
> print (urllib.request.urlopen(url).getcode())
>
> However, error message says: URLError:  getaddrinfo failed>
>
> Python 3.6.5 is being used to test whether url is live or not.
>
> Can anyone shed light on this?
>

What that's saying is that it couldn't look up the domain name to get
the corresponding address. Most likely, that means you either don't
have DNS available, or the DNS server said that it couldn't find that
server. (Whether that's true or not. It's always possible for the DNS
server to be wrong.) So, if you can fairly safely assume that you have
a fully-functioning internet connection (for instance, if other URLs
can be fetched successfully), the most reasonable interpretation of
this is that the URL is, in some way, broken.

I suspect that errno 11001 is a Winsock error, in which case it would
mean "Host not found". On my Linux system, I get a chained exception
that says "Name or service not found". Most likely, you can find this
information further up in the traceback.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: URLError:

2022-02-12 Thread Peter J. Holzer
On 2022-02-12 20:15:43 +, Shaozhong SHI wrote:
> The following is used in a loop to get response code for each url.
> 
> print (urllib.request.urlopen(url).getcode())
> 
> However, error message says: URLError:  getaddrinfo failed>
> 
> Python 3.6.5 is being used to test whether url is live or not.
> 
> Can anyone shed light on this?

getaddrinfo is the function that resolves a domain name into an IP
address. If that fails, either the domain name doesn't exist or you have
a problem with your DNS setup.

Things to test:

* Can you resolve the domain name to an address (try «nslookup» or
  «host» or «dig» depending on your OS)?
* Can you access the whole URL with a different tool like «wget» or
  «curl»?

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: URLError

2008-03-22 Thread Jim
On Mar 20, 7:03 pm, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
 On Thu, 20 Mar 2008 10:26:14 -0700, Jim wrote:
  The program is my first and I'm not a programmer so it will take me some
  time to get your recommendation to work. So far the program runs after I
  added code based on your example but the program still aborts and none
  of the code (Temporary failure, Skip/Halt/try Again? or Unknown
  response, boo hiss to you!) in your example is displayed.

 Try replacing the line:

 exceptURLError, e:

 with:

 except urllib2.URLError, e:

 and see if that helps.

 --
 Steven

Steven,

Got it to work with your example see code below. The process continued
bypassing the records when exceptions occurred.
My process displayed 'print here 1' then 'print here 4' and continued
process with next record without aborting. What
should be displayed, if anything, with the line response =
raw_input(Temporary failure,
Skip/Halt/try Again?) as I didn't see anything?

Thanks for your help
Jim

Code:
except urllib2.URLError, e:
   print here 1
   if e.errno == 10053:
  response = raw_input(Temporary failure, Skip/Halt/try
Again?)
  response = response.lower().strip()
   if response in ('h', 'halt'):
  print here 2
  break
   elif response in ('a', 'again', 't', 'try', 'try again'):
  print here 3
  continue
   elif response in ('', 's', 'skip'):
  print here 4
  lines -= 1
  continue
   else:
  print Unknown response, boo hiss to you!
  raise
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: URLError

2008-03-20 Thread Jim
On Mar 19, 6:50 pm, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
 On Wed, 19 Mar 2008 14:45:39 -0700, Jim wrote:
  Program randomly aborts when looking up url. The program loop thru
  4000+ records looking
  up ID via internet and returnshtmlcode which is used in subsequent
  processing. The code
  for looking-up record is below followed by abort details. Can anyone
  help with catching the
  abort before program aborts or provide code to automatically start
  program?

 Yes. Wrap the offending code with a try...except loop, something similar
 to this.

 try:
 contents = urllib2.urlopen(url).read()
 except URLError, e:
 if e.errno == 10053:
 # Software caused connection abort
 response = raw_input(
 Temporary failure, Skip/Halt/try Again?)
 response = response.lower().strip()
 if response in ('h', 'halt'):
 break
 elif response in ('a', 'again', 't', 'try', 'try again'):
 continue
 elif response in ('', 's', 'skip'):
 lines -= 1
 continue
 else:
 print Unknown response, boo hiss to you!
 raise

 --
 Steven

Thanks Steven for recommendation.

The program is my first and I'm not a programmer so it will take me
some time to get your recommendation to work. So far the program runs
after I added code based on your example but the program still aborts
and none of the code (Temporary failure, Skip/Halt/try Again? or
Unknown response, boo hiss to you!) in your example is displayed. It
appears to abort in the imported module urllib2 which is open
source. The code in urllib2 is way over my skill level.

Jim
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: URLError

2008-03-20 Thread Steven D'Aprano
On Thu, 20 Mar 2008 10:26:14 -0700, Jim wrote:

 The program is my first and I'm not a programmer so it will take me some
 time to get your recommendation to work. So far the program runs after I
 added code based on your example but the program still aborts and none
 of the code (Temporary failure, Skip/Halt/try Again? or Unknown
 response, boo hiss to you!) in your example is displayed.


Try replacing the line:

except URLError, e:


with:

except urllib2.URLError, e:


and see if that helps.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: URLError

2008-03-19 Thread Steven D'Aprano
On Wed, 19 Mar 2008 14:45:39 -0700, Jim wrote:

 Program randomly aborts when looking up url. The program loop thru 
 4000+ records looking
 up ID via internet and returns html code which is used in subsequent
 processing. The code
 for looking-up record is below followed by abort details. Can anyone
 help with catching the
 abort before program aborts or provide code to automatically start
 program? 


Yes. Wrap the offending code with a try...except loop, something similar 
to this.


try:
contents = urllib2.urlopen(url).read()
except URLError, e:
if e.errno == 10053:
# Software caused connection abort
response = raw_input(
Temporary failure, Skip/Halt/try Again?)
response = response.lower().strip()
if response in ('h', 'halt'):
break
elif response in ('a', 'again', 't', 'try', 'try again'):
continue
elif response in ('', 's', 'skip'):
lines -= 1
continue
else:
print Unknown response, boo hiss to you!
raise


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urlerror, urllib2: no address ... why or debug tips?

2006-03-10 Thread Rene Pijlman
[EMAIL PROTECTED]:
Help please with a URLError.

Post your code (a small self-contained example, preferrably) and the URL.

-- 
René Pijlman
-- 
http://mail.python.org/mailman/listinfo/python-list