How can I determine an HTTPMessage ?

K

Kevin

Can you tell me what to look for in an HTTPMessage that is an error? I
have looked at the header objects and I cannot determine an error
message.
 
P

Peter Hansen

Kevin said:
Can you tell me what to look for in an HTTPMessage that is an error? I
have looked at the header objects and I cannot determine an error
message.

I think you're missing most of the context and detail that would help us
provide a useful answer for you.

Think about it from a reader's point of view. We don't know what
packages you are using, we don't know what you mean by "HTTPMessage" (is
it a specific class, or is it just how you refer to the more generic
"HTTP message" entity?), we don't know what version of anything you are
using or what platform you're on.

-Peter
 
S

Steve Holden

Kevin said:
Can you tell me what to look for in an HTTPMessage that is an error? I
have looked at the header objects and I cannot determine an error
message.
I was thinking of a number between one and a thousand, and I forgot it.
Could someone please remind me what it was?

regards
Steve
 
D

David Murmann

Steve said:
I was thinking of a number between one and a thousand, and I forgot it.
Could someone please remind me what it was?

import smtplib

server = smtplib.SMTP('your.favorite.smtp.relay')

msg = """From: Spambot
To: (e-mail address removed)

Hi!
is it %d?
"""

for i in range(1, 1001):
server.sendmail('Spambot', '(e-mail address removed)', msg % i)

server.quit()

# could it be considered dangerous to post such code? ;)
 
J

Jorge Godoy

Steve Holden said:
I was thinking of a number between one and a thousand, and I forgot it. Could
someone please remind me what it was?

3.14159265352....

--
Jorge Godoy <[email protected]>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.
 
F

Fredrik Lundh

Steve said:
Thanks. This is *such* a helpful group. I'll write it down this time.

or you can look it up in the HTTP specification the next time you
need it.

</F>
 
P

Peter Hansen

Steve said:
Thanks. This is *such* a helpful group. I'll write it down this time.

Anticipating the next such incident, I borrowed the time machine and put
the answer on a web site for you for when you know the question:

http://random.org/cgi-bin/randnum?num=1&max=1000

No need to thank me now either -- I bumped into you while I was there
and you have will-been thanked me then. (I also bought you a beer, so
now you owe me one.)

Cheers,
-Peter
 
P

Paul Boddie

Peter said:
I think you're missing most of the context and detail that would help us
provide a useful answer for you.

Here's some of your own medicine. ;-)

A Google search for "HTTPMessage Python" produced a link to the
surprisingly helpful "urllib2 - The Missing Manual" [1]. This states
that the result of urlopen can be queried using the info method; for
example:

import urllib2
try:
f = urllib2.urlopen(some_url)
message = f.info()
except urllib2.HTTPError, exc:
message = exc.info()

One would guess that the status attribute on the above message object
would yield some kind of descriptive response from the server, noting
that the response code from the server is itself typically found as the
code attribute on either the f or exc objects manipulated in the above
example. However, my limited experiments show that status is typically
set to the empty string, although a perusal of the source code for
httplib reveals that the status attribute is only used to signal
exceptional conditions in the processing of responses, and I would
guess that most HTTP interactions wouldn't result in anything special
being put in that attribute.

I suppose what one could do is to examine f.code or exc.code and then
interpret that value accordingly (see the httplib module for the HTTP
response code constants) possibly generating a suitable message,
although the only place in the standard library that helps here is the
BaseHTTPRequestHandler class:

import BaseHTTPServer
message, description = \
BaseHTTPServer.BaseHTTPRequestHandler.responses[f.code]

Paul

P.S. It's a shame that the time spent by various other contributors in
making unhelpful remarks in response to the original, albeit imprecise
query wasn't spent in offering just a little helpful advice instead. I
guess such horseplay is how the Python community gets its "arrogant"
label...

[1] http://www.voidspace.org.uk/python/articles/urllib2.shtml
 
P

Peter Hansen

Paul said:
Here's some of your own medicine. ;-)

A Google search for "HTTPMessage Python" produced a link to the

A reasonable search to do, but one which might well have resulted in
lots of work that was completely off base. It seemed quite possible to
me that the OP, clearly not experienced in this area, was simply
referring to an "HTTP message", and I try not to spend lots of time on
potentially wild goose chases when a simple request for more info could
produce the certainty needed to avoid lots of guessing. (Plus, arrogant
though it might be, I feel that being direct and public about the need
for proper background info, true replicas of error tracebacks, platform
info, etc, may actually help reduce the recent apparent surge in folks
who seem to be new to support forums and the etiquette thereof. I know,
it's probably a lost cause, but I'm still an idealist.)

It will be interesting to see how accurately you've guessed at what the
OP needed. My hat's off to you in advance if you hit the nail on the
head...

-Peter
 
E

EP

if you bought him a beer in the future he would owe you less than a
beer today due to the time value of beer (which is, amazingly, much
greater than the time value of money) If he buys you a beer today, you
will need to go back to the future, and we must all hope this equation
converges on an cross-time equilibrium when dealing only in integer
beers. ("call me XAH!")

....

in case the OP was looking for HTTP codes, there is a list here (among
many other places) http://paradigmb.com/httpCodes.txt.

now the OP may ask "How do I determine the HTTP response code when I am
using the urllib2 module such as in the following code: ..."

but we will wait for that question (I propose) so as not to force the
OP into serious future-beer debt.

EP
 
S

Steve Holden

Peter said:
Anticipating the next such incident, I borrowed the time machine and put
the answer on a web site for you for when you know the question:

http://random.org/cgi-bin/randnum?num=1&max=1000

No need to thank me now either -- I bumped into you while I was there
and you have will-been thanked me then. (I also bought you a beer, so
now you owe me one.)

Your memory's getting terrible, Peter. I will have bought you three
beers the day before you will have bought me that one. Anyway, "*now*
you owe me one" is clearly wrong: "*then* you owe me one" should
actually have been "*then* I'll only owe you two".

regards
Steve
 
K

Kevin

Thanks, I was trying to get it to work with urllib instead of urllib2.
The code below works. Thanks.

import urllib2 as myurl

url = "some url"

try:
myurl.urlopen(url)
print "Redirecting to %s\n" % url
return url
except:
print "An invalid login_query was specified. Redirecting to
prefedit.psp with an error message.\n"
return "prefedit.psp?uname=%s&err=Invalid%%20login%%20query."
%(username)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,279
Messages
2,571,387
Members
48,089
Latest member
H_coding

Latest Threads

Top