Ejemplo n.º 1
0
    def _request(self, url, data, log_exceptions=True, attempts=3):
        data = {'data': json.dumps(data)}
        body = urlencode(data).encode('utf-8')

        page = self._fetch(url, body, log_exceptions, attempts)
        result = json.loads(page)
        return result["response"]
Ejemplo n.º 2
0
Archivo: rpc.py Proyecto: ystopia/luigi
    def _request(self, url, data, log_exceptions=True, attempts=3):
        data = {'data': json.dumps(data)}
        body = urlencode(data).encode('utf-8')

        page = self._fetch(url, body, log_exceptions, attempts)
        result = json.loads(page)
        return result["response"]
Ejemplo n.º 3
0
 def _fetch(obj, url, body, *args, **kwargs):
     body = urlencode(body).encode('utf-8')
     response = self.fetch(url, body=body, method='POST')
     if response.code >= 400:
         raise luigi.rpc.RPCError(
             'Errror when connecting to remote scheduler')
     return response.body.decode('utf-8')
Ejemplo n.º 4
0
 def _fetch(obj, url, body, *args, **kwargs):
     body = urlencode(body).encode('utf-8')
     response = self.fetch(url, body=body, method='POST')
     if response.code >= 400:
         raise luigi.rpc.RPCError(
             'Errror when connecting to remote scheduler'
         )
     return response.body.decode('utf-8')
Ejemplo n.º 5
0
    def _create_request(self, full_url, body=None):
        # when full_url contains basic auth info, extract it and set the Authorization header
        url = urlparse(full_url)
        if url.username:
            # base64 encoding of username:password
            auth = base64.b64encode(six.b('{}:{}'.format(url.username, url.password or '')))
            if six.PY3:
                auth = auth.decode('utf-8')

            # update full_url and create a request object with the auth header set
            full_url = url._replace(netloc=url.netloc.split('@', 1)[-1]).geturl()
            req = Request(full_url)
            req.add_header('Authorization', 'Basic {}'.format(auth))
        else:
            req = Request(full_url)

        # add the request body
        if body:
            req.data = urlencode(body).encode('utf-8')

        return req
Ejemplo n.º 6
0
 def fetch(self, full_url, body, timeout):
     body = urlencode(body).encode('utf-8')
     return urlopen(full_url, body, timeout).read().decode('utf-8')
Ejemplo n.º 7
0
 def fetch(self, full_url, body, timeout):
     try:
         body = urlencode(body).encode('utf-8')
         return urlopen(full_url, body, timeout).read().decode('utf-8')
     except (URLError, socket.timeout) as e:
         raise FetcherException(e)
Ejemplo n.º 8
0
 def fetch(self, full_url, body, timeout):
     body = urlencode(body).encode("utf-8")
     return urlopen(full_url, body, timeout).read().decode("utf-8")