Exemplo n.º 1
0
    def get_response(self, request):
        if request.method.upper() == "GET":
            res = requests.get(
                request.url,
                headers = request.headers,
                params = request.params
            )

        elif request.method.upper() == "POST":
            res = requests.post(
                request.url,
                headers = request.headers,
                params = request.params,
                data = request.data
            )
        else:
            raise Exception("ERROR : 不支持该请求方法")

        logger.info(u"[{}] <{}>".format(res.status_code, res.url))
        return Response(
            res.url,
            res.status_code,
            res.headers,
            res.content
        )
Exemplo n.º 2
0
    def get_response(self,request):
        # 判断请求方法
        if request.method.upper() == "GET":
            response = requests.get(
                url=request.url,
                headers=request.headers,
                cookies=request.cookies,
                params=request.params,
            )
        elif request.method.upper() == "POST":
            response=request.post(
                url=request.url,
                headers=request.headers,
                cookies=request.cookies,
                params=request.params,
                data=request.data
            )
        else:
            raise Exception('框架不支持的请求类型 {}'.format(request.method))

        logger.info("下载器成功获取<{}>对应的响应".format(request.url))

        # 构建响应对象
        res = Response(
            url=response.url,
            body=response.content,
            headers=response.headers,
            code=response.status_code,
            request=request,
            meta=request.meta
        )
        return res
Exemplo n.º 3
0
    def get_response(self, request):
        # 发送请求获取响应
        if request.method.upper() == 'GET':
            resp = requests.get(request.url, headers=request.headers)
        elif request.method.upper() == 'POST':
            resp = requests.post(request.url,
                                 headers=request.headers,
                                 data=request.data)
        else:
            raise Exception('不支持的发送请求的方式:{}'.format(request.method))

        return Response(url=resp.url,
                        status_code=resp.status_code,
                        headers=resp.headers,
                        body=resp.content)
Exemplo n.º 4
0
    def get_response(self, request):
        # 接收request,发送请求获取响应并构造返回

        # 's123x'.upper() == 'S123X'
        if request.method.upper() == 'GET':
            resp = requests.get(url=request.url, headers=request.headers)
        elif request.method.upper() == 'POST':
            resp = requests.post(url=request.url,
                                 headers=request.headers,
                                 data=request.data)
        else:
            # 如果方法不是get或者post,抛出一个异常
            raise Exception("不支持的请求方法")

        return Response(url=resp.url,
                        status_code=resp.status_code,
                        headers=resp.headers,
                        body=resp.content)
Exemplo n.º 5
0
 def get_response(self, request):
     '''发起请求获取响应的方法'''
     # 1. 根据请求对象,发起请求,获取响应
     #    判断请求方法:
     if request.method.upper() == 'GET':
         resp = requests.get(request.url,
                             headers=request.headers,
                             params=request.params)
     elif request.method.upper() == 'POST':
         resp = requests.post(request.url,
                              headers=request.headers,
                              params=request.params,
                              data=request.data)
     else:
         # 如果方法不是get或者post,抛出一个异常
         raise Exception("不支持的请求方法")
     # 2. 构建响应对象,并返回
     return Response(resp.url, resp.status_code, resp.headers, resp.content)
Exemplo n.º 6
0
    def get_response(self, request):
        if request.method == "GET":
            response = requests.get(request.url,
                                    headers=request.headers,
                                    params=request.params)
        elif request.method == "POST":
            response = requests.get(request.url,
                                    headers=request.headers,
                                    data=request.data)

        else:
            raise Exception("不支持{}请求方式".format(request.method))

        return Response(url=response.url,
                        code=response.status_code,
                        headers=response.headers,
                        body=response.content,
                        request=request)
Exemplo n.º 7
0
    def get_response(self, request):
        # 判断请求方式
        if request.method == 'GET':
            # 使用第三方request是获取的response,不是自定义的response对象类型
            response = requests.get(request.url, headers=request.headers, params=request.params)
        elif request.method == 'POST':
            response = requests.post(request.url, headers=request.headers, data=request.data)
        else:
            raise Exception('Not support the way of "{}", please use "GET" or "POST" to request.'.format(request.method))

        # 将下载的数据返回给引擎
        return Response(
            url=response.url,
            headers=response.headers,
            request=request,
            body=response.content,
            code=response.status_code,
        )
Exemplo n.º 8
0
    def get_response(self, request):
        """发起请求获取响应的方法"""
        #1.根据请求对象,发起请求,获取响应
        #判断请求方法
        if request.method.upper() == 'GET':
            resp = requests.get(request.url, headers=request.headers)

        elif request.method.upper() == 'POST':
            resp = requests.post(request.url,
                                 headers=request.headers,
                                 data=request.data)
        else:
            # 如果不是get或者post请求抛出异常
            raise Exception('不支持的请求方法')
        # 2.构建响应对象,并返回
        return Response(url=resp.url,
                        status_code=resp.status_code,
                        headers=resp.headers,
                        body=resp.content)
Exemplo n.º 9
0
    def get_response(self, request):
        # 判断请求方法
        if request.method.upper() == 'GET':
            resp = requests.get(request.url,
                                headers=request.headers,
                                params=request.params)

        elif request.method.upper() == "POST":
            resp = requests.post(request.url,
                                 headers=request.headers,
                                 params=request.params,
                                 data=request.data)

        else:
            raise Exception('不支持的请求方法')

        # 返回响应对象
        return Response(url=resp.url,
                        status_code=resp.status_code,
                        headers=resp.headers,
                        body=resp.content)
Exemplo n.º 10
0
 def get_response(self, request):
     """
     实现结构请求对象,发送请求,获取响应
     :param request:
     :return:
     """
     if request.method.upper() == "GET":
         resp = requests.get(request.url,
                             headers=request.headers,
                             params=request.params)
     elif request.method.upper() == "POST":
         resp = requests.post(request.url,
                              headers=request.headers,
                              params=request.params,
                              data=request.data)
     else:
         raise Exception("不支持的请求方法:<{}>".format(request.method))
     logger.info("<{}    {}> ".format(resp.status_code, resp.url))
     return Response(url=resp.url,
                     body=resp.content,
                     headers=resp.headers,
                     status_code=resp.status_code)
Exemplo n.º 11
0
    def get_response(self, request):

        # 判断请求类型,根据请求类型做不同的请求
        if request.method.upper() == "GET":
            res = requests.get(url=request.url,
                               headers=request.headers,
                               params=request.params)
        elif request.method.upper() == "POST":
            res = requests.post(url=request.url,
                                headers=request.headers,
                                params=request.params,
                                data=request.data)
        else:
            raise Exception('该框架目前不支持{}类型的请求'.format(request.method))

        # 构建响应对象
        response = Response(url=res.url,
                            headers=res.headers,
                            code=res.status_code,
                            body=res.content)

        # 将创建好的相应对象返回
        return response