SunQuest
           Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old November 17th, 2003, 11:43 PM
sad.machine sad.machine is offline
I hate nerds
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jul 2003
Posts: 533 sad.machine Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 20 h 48 m 41 sec
Reputation Power: 0
network programming!

heres the problem, i need to retrieve a webpage given a url.

using

h = httplib.HTTP(hostport)
h.putrequest('GET', abspath)

is a problem because if the url is "http://www.whatever.com", then absolute path is "" and that wont work.

using

h = urllib.urlopen(URL)

is a problem because it wont detect a 404 error!

i need a little bit of both. there must be some way to get the status code using urlopen, right?

Reply With Quote
  #2  
Old November 18th, 2003, 02:21 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 18 m 50 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Surly all you have to do with urllib is to check for the 404 or 500 error strings (the page title would be the easiest thing to test) couldnt be simpler.

If you really want a module to handle this i think urllib2 should work

Another way to do this would be to manipulate the abspath, python has a greate module to do this kind of thing! (os.path)

Oh, i've tried both ways (httplib and urllib) how exactly are you detecting these errors? No special headers are sent as far as i can see..

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #3  
Old November 18th, 2003, 02:46 AM
Igor Pechersky Igor Pechersky is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 28 Igor Pechersky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Did you try to go in opposite way - use urllib.URLopener, and proceed HTTP-EQUIV if needed?

Last edited by Igor Pechersky : November 18th, 2003 at 02:50 AM.

Reply With Quote
  #4  
Old November 18th, 2003, 05:22 AM
Grim Archon's Avatar
Grim Archon Grim Archon is offline
Mini me.
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2003
Location: Cambridge, UK
Posts: 783 Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)Grim Archon User rank is Corporal (100 - 500 Reputation Level)  Folding Points: 1488 Folding Title: Novice Folder
Time spent in forums: 3 Days 2 h 15 m 57 sec
Reputation Power: 7
Send a message via MSN to Grim Archon
I guess it's a Zope thing so you use 1.5.2 code?

But in 2.x ...

import httplib
hostport = 'www.bbc.co.uk'
abspath = ''
# abspath = '/' works too

h = httplib.HTTPConnection(hostport)
h.request('GET', abspath)
resp = h.getresponse()

if resp.status == 200:
data = resp.read()
print data
else:
print "Error"

Reply With Quote
  #5  
Old November 18th, 2003, 10:05 PM
sad.machine sad.machine is offline
I hate nerds
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jul 2003
Posts: 533 sad.machine Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 20 h 48 m 41 sec
Reputation Power: 0
thanks guys.

im actually using urllib2 now and it works fine.

the only thing is that i need to detect a timeout.

how to do this besides getting down to the socket level?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > network programming!


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway