当前位置: 首页>>代码示例>>Python>>正文


Python grequests.post方法代码示例

本文整理汇总了Python中grequests.post方法的典型用法代码示例。如果您正苦于以下问题:Python grequests.post方法的具体用法?Python grequests.post怎么用?Python grequests.post使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在grequests的用法示例。


在下文中一共展示了grequests.post方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: whatweb

# 需要导入模块: import grequests [as 别名]
# 或者: from grequests import post [as 别名]
def whatweb(self):
        response = requests.get(self.url, verify=False)
        whatweb_dict = {"url": response.url, "text": response.text,
                        "headers": dict(response.headers)}
        whatweb_dict = json.dumps(whatweb_dict)
        whatweb_dict = whatweb_dict.encode()
        whatweb_dict = zlib.compress(whatweb_dict)
        data = {"info": whatweb_dict}
        result_infos = requests.post("http://whatweb.bugscaner.com/api.go", files=data)
        content = result_infos.json()

        if "CMS" in content.keys():
            return content['CMS'][0]
        elif "Message Boards" in content.keys():
            return content['Message Boards'][0]
        else:
            return '未知CMS'


# 漏洞检测 
开发者ID:ParrotSec-CN,项目名称:ParrotSecCN_Community_QQbot,代码行数:22,代码来源:hack_api.py

示例2: exploitpoc

# 需要导入模块: import grequests [as 别名]
# 或者: from grequests import post [as 别名]
def exploitpoc(self):
        for poctype in [
            'cms',
            'system',
            'industrial',
            'information',
                'hardware']:
            tasks = [
                grequests.post(
                    "http://tools.hexlt.org/api/" +
                    poctype,
                    json={
                        "url": self.url,
                        "type": type}) for type in self.poclist[poctype]]
            res = grequests.map(tasks, size=30)
            for i in res:
                result = i.json()
                if result['status']:
                    self.result.append(result['pocresult'])
        return self.result  # exp利用成功以列表形式返回结果,否则返回空列表 [] 
开发者ID:ParrotSec-CN,项目名称:ParrotSecCN_Community_QQbot,代码行数:22,代码来源:hack_api.py

示例3: get_url

# 需要导入模块: import grequests [as 别名]
# 或者: from grequests import post [as 别名]
def get_url(url, abort_on_error=False, is_json=True, fetch_timeout=5, auth=None, post_data=None):
    """
    @param post_data: If not None, do a POST request, with the passed data (which should be in the correct string format already)
    """
    headers = {'Connection': 'close', }  # no keepalive
    if auth:
        # auth should be a (username, password) tuple, if specified
        headers['Authorization'] = http_basic_auth_str(auth[0], auth[1])

    try:
        if post_data is not None:
            if is_json:
                headers['content-type'] = 'application/json'
            r = grequests.map((grequests.post(url, data=post_data, timeout=fetch_timeout, headers=headers, verify=False),))[0]
        else:
            r = grequests.map((grequests.get(url, timeout=fetch_timeout, headers=headers, verify=False),))[0]
        if r is None:
            raise Exception("result is None")
    except Exception as e:
        raise Exception("Got get_url request error: %s" % e)
    else:
        if r.status_code != 200 and abort_on_error:
            raise Exception("Bad status code returned: '%s'. result body: '%s'." % (r.status_code, r.text))
    return r.json() if r.text and is_json else r.text 
开发者ID:CounterpartyXCP,项目名称:counterblock,代码行数:26,代码来源:util.py

示例4: make_request

# 需要导入模块: import grequests [as 别名]
# 或者: from grequests import post [as 别名]
def make_request(id, wav):
    url = 'http://localhost:8000/recognize?lang=en-towninfo&id=' + str(id)
    headers = {'Content-Type': 'audio/x-wav; rate=44100;'}

    return grequests.post(url, data = wav, headers = headers) 
开发者ID:UFAL-DSG,项目名称:cloud-asr,代码行数:7,代码来源:benchmark_batch_recognition.py

示例5: post

# 需要导入模块: import grequests [as 别名]
# 或者: from grequests import post [as 别名]
def post(self, url, data=None, json=None, **kwargs):
        """HTTP POST Method."""
        if data is not None:
            kwargs['data'] = data
        if json is not None:
            kwargs['json'] = json

        kwargs['auth'] = self.auth

        req = grequests.post(url, **kwargs)
        return self._run(req) 
开发者ID:ArangoDB-Community,项目名称:pyArango,代码行数:13,代码来源:gevent_session.py

示例6: annotate_multiple

# 需要导入模块: import grequests [as 别名]
# 或者: from grequests import post [as 别名]
def annotate_multiple(self, text, properties=None):

        assert isinstance(text, list)

        if properties is None:
            properties = {}
        else:
            assert isinstance(properties, dict)

        # Checks that the Stanford CoreNLP server is started.
        # try:
        #     requests.get(self.server_url)
        # except requests.exceptions.ConnectionError:
        #     raise Exception('Check whether you have started the CoreNLP server e.g.\n'
        #     '$ cd stanford-corenlp-full-2015-12-09/ \n'
        #     '$ java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer')

        def _post(data):
            r = grequests.post(self.server_url,
                               params={'properties': str(properties)},
                               data=data,
                               headers={'Connection': 'close'})
            return r

        reqs = (_post(data.encode()) for data in text)

        results = grequests.imap(reqs)

        ret = []
        for result in results:
            output = ''
            if 'outputFormat' in properties and properties['outputFormat'] == 'json':
                try:
                    output = json.loads(result.text, encoding='utf-8', strict=False)
                except Exception as e:
                    print(e)
                    print(' --', 'WHAT THE FLYING SQUIRREL ?!')
                    pass
            ret.append(output)
        return ret 
开发者ID:uclnlp,项目名称:d4,代码行数:42,代码来源:corenlp.py

示例7: annotate

# 需要导入模块: import grequests [as 别名]
# 或者: from grequests import post [as 别名]
def annotate(self, text, properties=None):
        assert isinstance(text, str)
        if properties is None:
            properties = {}
        else:
            assert isinstance(properties, dict)

        # Checks that the Stanford CoreNLP server is started. (commented out to speed it up)
        # try:
        #     requests.get(self.server_url)
        # except requests.exceptions.ConnectionError:
        #     raise Exception('Check whether you have started the CoreNLP server e.g.\n'
        #     '$ cd stanford-corenlp-full-2015-12-09/ \n'
        #     '$ java -mx4g -cp "*" edu.stanford.nlp.pipeline.StanfordCoreNLPServer')

        data = text.encode()

        r = requests.post(
            self.server_url, params={
                'properties': str(properties)
            }, data=data, headers={'Connection': 'close'})
        r.encoding = 'utf-8'
        output = r.text
        if ('outputFormat' in properties
             and properties['outputFormat'] == 'json'):
            try:
                output = json.loads(output, encoding='utf-8', strict=False)
            except:
                pass
        return output 
开发者ID:uclnlp,项目名称:d4,代码行数:32,代码来源:corenlp.py

示例8: call_jsonrpc_api

# 需要导入模块: import grequests [as 别名]
# 或者: from grequests import post [as 别名]
def call_jsonrpc_api(method, params=None, endpoint=None, auth=None, abort_on_error=False, use_cache=True):
    if not endpoint:
        endpoint = config.COUNTERPARTY_RPC
    if not auth:
        auth = config.COUNTERPARTY_AUTH
    if not params:
        params = {}

    if use_cache:
        # check for cached response for the current block and return that if it exists
        cache_key = "{}__{}__{}__{}".format(
            endpoint,
            method,
            hashlib.sha256(json.dumps(params).encode('utf-8')).hexdigest(),
            config.state['my_latest_block']['block_index'])
        result = cache.get_value(cache_key)
        #logger.debug("{} -- {}, {} ====> {}".format('HIT' if result is not None else 'MISS', method, hashlib.sha256(json.dumps(params).encode('utf-8')).hexdigest(), json.dumps(params)[0:2000]))
        if result is not None:
            return result

    payload = {
        "id": 0,
        "jsonrpc": "2.0",
        "method": method
    }
    if params:
        payload['params'] = params

    headers = {
        'Content-Type': 'application/json',
        'Connection': 'close',  # no keepalive
    }
    if auth:  # auth should be a (username, password) tuple, if specified
        headers['Authorization'] = http_basic_auth_str(auth[0], auth[1])

    try:
        r = grequests.map((grequests.post(endpoint, data=json.dumps(payload), timeout=JSONRPC_API_REQUEST_TIMEOUT, headers=headers),))
        r = r[0]
        if r is None:
            raise Exception("result is None -- is the '{}' endpoint operational?".format(endpoint))
    except Exception as e:
        raise Exception("Got call_jsonrpc_api request error: %s" % e)
    else:
        if r.status_code != 200:
            if abort_on_error:
                raise Exception("Bad status code returned: '%s'. result body: '%s'." % (r.status_code, r.text))
            else:
                logging.warning("Bad status code returned: '%s'. result body: '%s'." % (r.status_code, r.text))
                result = None
        else:
            result = r.json()

    if abort_on_error and 'error' in result and result['error'] is not None:
        raise Exception("Got back error from server: %s" % result['error'])

    if use_cache:
        # store the result
        cache.set_value(cache_key, result, cache_period=JSONRPC_CACHE_PERIOD)

    return result 
开发者ID:CounterpartyXCP,项目名称:counterblock,代码行数:62,代码来源:util.py


注:本文中的grequests.post方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。