473,408 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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

103 100+
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.

2 1564
bvdet
2,851 Expert Mod 2GB
Encapsulate the request for urls in a while loop. Break the loop with a valid result to proceed.
Aug 16 '14 #2
gintare
103 100+
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

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

Similar topics

7
by: Alex Hunsley | last post by:
I'm making a web site that does login authentication. It all works fine, but I have a question about 'correctness'... Certain php scripts on the site should only run in the user has logged on....
5
by: fwells11 | last post by:
Hi there. As you will see from my questions, I am an SQL newb. I dabble but never get to spend enough time to get proficient so base any feeedback on that basis please. This is all theoretical...
0
by: Janning Vygen | last post by:
Hi, i have a question about how to handle postgresql constraint errors in the client app. I found some mails in the archive about it, too. But i have still so many questions about how to do it,...
7
by: cbrown | last post by:
I am looking for a method (maybe even a commercially available piece of software) to watch a program and ensure that it is always running. If it is killed in task manager, it will automatically...
1
by: Sebitti | last post by:
I'm getting timeout error in my client application (asp.net client) when I call a web service that is taking some time (2 - 3 minutes). How can I configure the timeout limit? Current...
6
by: Ted | last post by:
I am construvcting a number of databases, some of which contain sensitive data and most of which do not. I am attempting to handle the security issues involved in protecting sensitive data in part...
5
by: This | last post by:
I have a pretty basic emailing script that sends a relatively small number (150) of html emails. The emails are compiled, personalised from a mysql db subscribers list, and sent using mail() -...
3
by: sophie_newbie | last post by:
Hi, I have a cgi script that performs a very long computation that can take several hours to complete. Is there any smart way that I can keep this script running until it is finished (after the...
2
by: silk.odyssey | last post by:
I am getting the following error trying to download an html page using urllib2. urllib2.HTTPError: HTTP Error 204: NoContent The url is of this type: ...
3
sbouley7
by: sbouley7 | last post by:
I've been working with VBA in Access for a while and with the help of Google can figure out most things on my own but this one has got me stumped. I've created running totals in the past with no...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.