python Python中的“result.status_code == 200”是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1892161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does "result.status_code == 200" in Python mean?
提问by brilliant
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)
回答by fyjham
It's a HTTP status code, it means "OK" (EG: The server successfully answered the http request).
这是一个 HTTP 状态码,表示“OK”(例如:服务器成功响应了 http 请求)。
回答by dan-gph
Whoever wrote that should have used a constant instead of a magic number. The httplib module has all the http response codes.
写那个的人应该使用常数而不是幻数。httplib 模块具有所有 http 响应代码。
E.g.:
例如:
>>> import httplib
>>> httplib.OK
200
>>> httplib.NOT_FOUND
404
回答by Wyzard
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.)
200 是“OK”的 HTTP 状态代码,成功响应。(您可能熟悉的其他代码是 404 Not Found、403 Forbidden 和 500 Internal Server Error。)
See RFC 2616for more information.
有关更多信息,请参阅RFC 2616。