207: ('multi_status','multiple_status','multi_stati','multiple_stati'), 208: ('already_reported',), 226: ('im_used',),# 重定向状态码300: ('multiple_choices',), 301: ('moved_permanently','moved','\\o-'), 302: ('found',), 303: ('see_other','other'), 304: ('not_modif...
response= requests.get("http://www.baidu.com")print(type(response.status_code),response.status_code) #< class'int'>200print(type(response.headers),response.headers) # 头部信息print(type(response.cookies),response.cookies) #<class'requests.cookies.RequestsCookieJar'><RequestsCookieJar[<Cookie BDO...
requests.status_code importrequests response=requests.get('http://www.jianshu.com/hello.html')exit()ifnot response.status_code==requests.codes.not_foundelseprint('404 Not Found') importrequests response=requests.get('http://www.jianshu.com')exit()ifnot response.status_code==200elseprint('R...
如果status_code不是200,产生异常requests.HTTPError r.raise_for_status()方法内部判断r.status_code是否等于200不需要增加额外的if语句,该语句便于利用try-except进行异常处理。 raise_for_status源码 def raise_for_status(self): """Raises stored :class:`HTTPError`, if one occurred.""" http_error_msg ...
exit() if not r.status_code == requests.codes.ok else print('Request Successfully') ===执行结果=== Request Successfully 1. 2. 3. 4. 5. 这里通过比较返回码和内置的成功的返回码,来保证请求得到了正常响应,输出成功请求的消息,否则程序终止。 这里我们用 requests.codes...
HTTP状态码(HTTP Status Code)是用以表示网页服务器HTTP响应状态的3位数字代码。status [ˈsteɪt...
HTTP状态码的英文为HTTP Status Code 常见的HTTP状态码: 200 - 请求成功 301 - 资源(网页等)被永久转移到其它URL 404 - 请求的资源(网页等)不存在 500 - 内部服务器错误 HTTP状态码由三个十进制数字组成,第一个十进制数字定义了状态码的类型,后两个数字没有分类的作用。HTTP状态码共分为5种类型: ...
print(response.status_code) #200 print(response.raise_for_status()) #none 原始响应(暂未看懂,先略过 定制请求头 如果想为请求添加 HTTP 头部,只要简单地传递一个 dict 给 headers 参数就可以了。 以知乎为例子 response =requests.get("https://www.zhihu.com") ...
print(response.status_code) # 输出响应内容类型 text print(type(response.text)) # 输出响应内容 print(response.text) # 输出cookies print(response.cookies) 1.2、各种请求方式 import requests # 发起POST请求 requests.post('http://httpbin.org/post') ...
412 Precondition FailedExpect this status code for the following types of errors: -ConcurrencyVersionMismatch -DuplicateRecordClient Error 429 Too Many RequestsExpect this status code when API limits are exceeded. More information:Service Protection API LimitsClient Error ...