473,379 Members | 974 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,379 software developers and data experts.

Multiple Error Handling


I am trying to input a spreadsheet of possible domain names and output the length of the sourcecode of the webpage (if it exists). In testing this, I’ve come across a lot of errors, for example, when websites ask for username/password, take too slow to load, or no longer work. I am a newbie and am looking for help dealing with multiple errors.

First, is the basic code setup below the best way to deal with multiple errors? I would like to have the program read the lines if possible, and return back null (or string=’’) if something goes wrong; do I have to do this ad hoc, adding new errors to my list each time I found one, or is there some way to say ‘return null if any error comes up?’

Second, how do I handle this error?

InvalidURL: nonnumeric port: ''

It seems to happen on z=urlopen('http://www.'+domainTerm)

Third, how do I handle this error?

error: (10054, 'Connection reset by peer')

It seems to happen on lineList=z.readlines()

Thank you,
Expand|Select|Wrap|Line Numbers
  1. from mechanize import Browser
  2. from urllib import urlopen
  3. import re, time, urllib2, string
  5. f = open('rawST2.csv','r')
  6. lines = f.readlines()
  7. f.close()
  8. f2 = open('toy4.csv','w')
  9. f2.write(lines[0].rstrip()+',sourcelines'+',sourcecharacters' +"\n")
  10. print(lines[0].rstrip()+",sourcelines"+",sourcecharacters)
  12. domainTerms=[]
  13. for i in range(1,len(lines)):
  14.     domainTerms.append( lines[i].split(',')[5].rstrip() )
  16. x = domainTerms[59]
  17. domainTerm=string.replace(x,x[0],"")
  19. try: 
  20.   z=urlopen('http://www.'+domainTerm)
  21.   lineList=z.readlines()
  22. except (urllib2.URLError, ValueError, IOError, AttributeError, TypeError):
  23.   lineList=""
Aug 19 '07 #1
0 1003

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

Similar topics

by: WSeeger | last post by:
When creating a new class, is it encouraged to always include error handling routines within your LET and GET procedures? It's seems that most text books never seem to include much about error...
by: RJ | last post by:
We currently send product releases to our customers, and often have to include scripts that need to be ran on the Oracle databases (also do it for SqlServer customers, but we use a different set of...
by: Disco-181 | last post by:
Hi, I have a script which isn't working in Mozilla based browser for some reason. I'm trying to run two functions from the body onload tag and it simply isn't happening. I have a cascading...
by: Squirrel | last post by:
I have a command button on a subform to delete a record. The only statement in the subroutine is: DoCmd.RunCommand acCmdDeleteRecord The subform's recordsource is "select * from tblVisit order...
by: Anthony England | last post by:
Everyone knows that global variables get re-set in an mdb when an un-handled error is encountered, but it seems that this also happens when the variable is defined as private at form-level. So...
by: metsys | last post by:
We have an ASP.NET 2.0 (C#) application that is divided into multiple layers. The multiple layers come from having a web project and 2 different class library projects in the same solution. I'm...
by: Carol | last post by:
Exception may be thrown in the code inside the try block. I want to handling the SqlException with State == 1 in a special way, and for all others I want to use a general way to handle. Which of...
by: Lysander | last post by:
Thought I would give something back with a few articles. This article is a bit of code to add error handling. When I have time, I want to write articles on multilingual databases, and Access...
by: MrDeej | last post by:
Hello guys! We have an SQL server which sometimes makes timeouts and connection errors. And we have an function witch writes and updates data in 2 tables on this server. When the SQL server error...
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.