本文整理匯總了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'
# 漏洞檢測
示例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利用成功以列表形式返回結果,否則返回空列表 []
示例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
示例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)
示例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)
示例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
示例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
示例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