473,327 Members | 2,103 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,327 software developers and data experts.

Multiple Error Handling

7
Hi,

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,
Mitch
Expand|Select|Wrap|Line Numbers
  1. from mechanize import Browser
  2. from urllib import urlopen
  3. import re, time, urllib2, string
  4.  
  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)
  11.  
  12. domainTerms=[]
  13. for i in range(1,len(lines)):
  14.     domainTerms.append( lines[i].split(',')[5].rstrip() )
  15.  
  16. x = domainTerms[59]
  17. domainTerm=string.replace(x,x[0],"")
  18.  
  19. try: 
  20.   z=urlopen('http://www.'+domainTerm)
  21.   lineList=z.readlines()
  22. except (urllib2.URLError, ValueError, IOError, AttributeError, TypeError):
  23.   lineList=""
  24.  
---
Aug 19 '07 #1
0 1002

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

Similar topics

2
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...
2
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...
3
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...
6
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...
21
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...
1
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...
2
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...
0
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...
9
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
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 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.