brilliant
brilliant

Reputation: 2617

What does "result.status_code == 200" in Python mean?

In this little piece of code, what is the fourth line all about?

from google.appengine.api import urlfetch
url = "http://www.google.com/"
result = urlfetch.fetch(url)
if result.status_code == 200:
    doSomethingWithResult(result.content)

Upvotes: 4

Views: 31005

Answers (3)

dan-gph
dan-gph

Reputation: 16909

Whoever wrote that should have used a constant instead of a magic number. The httplib module has all the http response codes.

E.g.:

>>> import httplib
>>> httplib.OK
200
>>> httplib.NOT_FOUND
404

Upvotes: 8

Wyzard
Wyzard

Reputation: 34563

200 is the HTTP status code for "OK", a successful response. (Other codes you may be familiar with are 404 Not Found, 403 Forbidden, and 500 Internal Server Error.)

See RFC 2616 for more information.

Upvotes: 6

fyjham
fyjham

Reputation: 7034

It's a HTTP status code, it means "OK" (EG: The server successfully answered the http request).

See a list of them here on wikipedia

Upvotes: 16

Related Questions