コード例 #1
0
ファイル: async_http.py プロジェクト: anstones/Mylib
    def upload_file(self, url, raw_data, filename=None, ext="jpg"):
        """

        :param url:
        :param raw_data:
        :param filename:
        :param ext:
        :return:
        """
        method = "POST"
        boundary = get_unique_id()
        body = AsyncRequest._encode_formdata(boundary=boundary,
                                             filename=filename,
                                             ext=ext,
                                             raw_data=raw_data)
        headers = {
            'Content-Type': 'multipart/form-data; boundary=%s' % boundary,
            'Content-Length': len(body)
        }
        result = AsyncResult()
        request = HTTPRequest(url=url,
                              method=method,
                              headers=headers,
                              body=body)
        try:
            response = yield self._client.fetch(request)
            if response.error:
                raise CallServiceException(method=method,
                                           url=url,
                                           errmsg=response.error)
            result.response = response
        except Exception as e:
            raise CallServiceException(method=method, url=url, errmsg=e)
        return result
コード例 #2
0
ファイル: async_http.py プロジェクト: anstones/Mylib
    def send_data_as_file(self, url, raw_data, filename=None, ext="jpg"):
        """

        :param url:
        :param filename:
        :param raw_data:
        :param ext:
        :return:
        """
        method = "POST"
        boundary = get_unique_id()
        headers = {
            'Content-Type': 'multipart/form-data; boundary=%s' % boundary
        }
        producer = partial(self._stream_producer, boundary, filename, ext,
                           raw_data)
        result = AsyncResult()
        request = HTTPRequest(url=url,
                              method=method,
                              headers=headers,
                              body_producer=producer)
        try:
            response = yield self._client.fetch(request)
            if response.error:
                raise CallServiceException(method=method,
                                           url=url,
                                           errmsg=response.error)
            result.response = response
        except Exception as e:
            raise CallServiceException(method=method, url=url, errmsg=e)
        return result
コード例 #3
0
ファイル: app.py プロジェクト: gigatesseract/ShopTikBackend
def getShopId():
    global nodes
    (ele, nodes) = u.get_unique_id(nodes, config_dict, tx_receipt)
    return ele