Python grequests.post() Examples
The following are 8
code examples of grequests.post().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
grequests
, or try the search function
.
Example #1
Source File: hack_api.py From ParrotSecCN_Community_QQbot with GNU General Public License v2.0 | 6 votes |
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' # 漏洞检测
Example #2
Source File: hack_api.py From ParrotSecCN_Community_QQbot with GNU General Public License v2.0 | 6 votes |
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利用成功以列表形式返回结果,否则返回空列表 []
Example #3
Source File: util.py From counterblock with MIT License | 6 votes |
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
Example #4
Source File: benchmark_batch_recognition.py From cloud-asr with Apache License 2.0 | 5 votes |
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)
Example #5
Source File: gevent_session.py From pyArango with Apache License 2.0 | 5 votes |
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)
Example #6
Source File: corenlp.py From d4 with MIT License | 5 votes |
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
Example #7
Source File: corenlp.py From d4 with MIT License | 5 votes |
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
Example #8
Source File: util.py From counterblock with MIT License | 4 votes |
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