Python requests 模块,models() 实例源码
我们从Python开源项目中,提取了以下3个代码示例,用于说明如何使用requests.models()。
def forward_request(self, method, path, data, headers):
""" This interceptor method is called by the proxy when receiving a new request
(*before* forwarding the request to the backend service). It receives details
of the incoming request, and returns either of the following results:
* True if the request should be forwarded to the backend service as-is (default).
* An integer (e.g., 200) status code to return directly to the client without
calling the backend service.
* An instance of requests.models.Response to return directly to the client without
calling the backend service.
* An instance of requests.models.Request which represents a new/modified request
that will be forwarded to the backend service.
* Any other value, in which case a 503 Bad Gateway is returned to the client
without calling the backend service.
"""
return True
def judge_response():
import requests
from requests.models import Response
body = requests.get("http://www.126.com")
if isinstance(body, Response):
print "yes"
else:
print "no"
def return_response(self, method, path, data, headers, response):
""" This interceptor method is called by the proxy when returning a response
(*after* having forwarded the request and received a response from the backend
service). It receives details of the incoming request as well as the response
from the backend service, and returns either of the following results:
* An instance of requests.models.Response to return to the client instead of the
actual response returned from the backend service.
* Any other value, in which case the response from the backend service is
returned to the client.
"""
return None