473,382 Members | 1,204 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,382 software developers and data experts.

Re: Retrieve Custom 404 page.

On Mon, 2008-11-17 at 13:59 -0800, godavemon wrote:
I'm using urllib2 to pull pages for a custom version of a web proxy
and am having issues with 404 errors. Urllib2 does a great job of
letting me know that a 404 happened with the following code.

import urllib2
url = 'http://cnn.com/asfsdafsadfasdf/'
try:
page = urllib2.urlopen( url )
except urllib2.URLError, e:
print e

returns: HTTP Error 404: Not Found
>From the urllib2 docs: HTTPError is also a valid HTTP response, so you
can treat an HTTP error as an exceptional event or a valid response:

import urllib2
url = 'http://cnn.com/asfsdafsadfasdf/'
try:
page = urllib2.urlopen(url)
except urllib2.URLError, e:
print e.read()
>
http://cnn.com/asdfasdfadsf

Nov 17 '08 #1
1 1750
Perfect! Thanks!

On Nov 17, 4:16*pm, Albert Hopkins <mar...@python.invalidwrote:
On Mon, 2008-11-17 at 13:59 -0800, godavemon wrote:
I'm using urllib2 to pull pages for a custom version of a web proxy
and am having issues with 404 errors. *Urllib2 does a great job of
letting me know that a 404 happened with the following code.
import urllib2
url = 'http://cnn.com/asfsdafsadfasdf/'
try:
* * page = urllib2.urlopen( url )
except urllib2.URLError, e:
* * print e
returns: HTTP Error 404: Not Found
From the urllib2 docs: HTTPError is also a valid HTTP response, so you

can treat an HTTP error as an exceptional event or a valid response:

import urllib2
url = 'http://cnn.com/asfsdafsadfasdf/'
try:
* * page = urllib2.urlopen(url)
except urllib2.URLError, e:
* * print e.read()
http://cnn.com/asdfasdfadsf

Nov 17 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Scott Zabolotzky | last post by:
I'm trying to pass a custom object back and forth between forms. This custom object is pulled into the app using an external reference to an assembly DLL that was given to me by a co-worker. A...
1
by: Paul W | last post by:
I've got Forms Authentication up and running. The starting page for the app. is default.aspx. I want to display on the top of this form a 'You are logged in as Fredxyz' message. If the user is a...
6
by: David Bowey | last post by:
Hi There! I'm writing a custom HttpHandler to create watermarks on my PNG images of my website. So typically, a PNG image is linked in an ASPX page as follows... <img src="images/test.png"...
0
by: Just Me | last post by:
I suppose I'd have to be extremely lucky to find someone who knows about what I now write but I have to try. Using PageSetupDialog and then clicking Printer and then Properties I can select...
0
by: george_Martinho | last post by:
It seems that the ASP.NET Microsoft team didn't think about this!! The profilemanager class has the following methods: - DeleteInactiveProfiles. Enables you to delete all profiles older than a...
0
by: ravescar | last post by:
I am currently working on an generic error collection mechanism in ASP.NET2.0 written using C# that can catch unhandled exception on a web application in application level. it automatically save an...
5
by: Henrik | last post by:
The problem is (using MS Access 2003) I am unable to retrieve long strings (255 chars) from calculated fields through a recordset. The data takes the trip in three phases: 1. A custom public...
0
by: Georg | last post by:
Hello, I'm using SSIS (SQL Server Integration Services) via Native Informix OLE DB provider to extract (ETL) data from Informix 7.3 to SQL Server 2005. I have following problem, when I try...
0
by: godavemon | last post by:
I'm using urllib2 to pull pages for a custom version of a web proxy and am having issues with 404 errors. Urllib2 does a great job of letting me know that a 404 happened with the following code. ...
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: 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...
0
isladogs
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
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,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
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
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...
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...

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.