By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,905 Members | 2,083 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,905 IT Pros & Developers. It's quick & easy.

how to keep script running despite urlib.error.HTTPerror, http.client.HTTPResponse o

100+
P: 103
I would like that script would keep running, i.e. requesting urls with different words, depite errors.
Currently script stops running if error occurs.
Expand|Select|Wrap|Line Numbers
  1. #word comes from the list of words
  2. res6="http://glosbe.com/en/el/"+word
  3. try:
  4.   resp = urllib.request.urlopen(res)
  5.   if resp.getcode() == 200:
  6.       html = resp.read()
  7.       #proceed with result...
  8. except urlib.error.HTTPerror as e :
  9.   print(str(e.getcode()))
  10.   #proceed with error...
Aug 16 '14 #1

✓ answered by bvdet

Encapsulate the request for urls in a while loop. Break the loop with a valid result to proceed.

Share this Question
Share on Google+
2 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
Encapsulate the request for urls in a while loop. Break the loop with a valid result to proceed.
Aug 16 '14 #2

100+
P: 103
Thanks. The final code looks like:

Expand|Select|Wrap|Line Numbers
  1.  
  2.     #word comes from the list of words
  3.     res6="http://glosbe.com/en/el/"+word
  4.     try:
  5.       while(urllib.request.urlopen(res)):
  6.         resp = urllib.request.urlopen(res)
  7.         if resp.getcode() == 200 : break 
  8.       if resp.getcode() == 200:
  9.       html = resp.read()
  10.       #proceed with result...
  11.     except urllib.error.HTTPError as e :
  12.       #proceed with error...
Aug 16 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.