本文整理匯總了Python中requests.post方法的典型用法代碼示例。如果您正苦於以下問題:Python requests.post方法的具體用法?Python requests.post怎麽用?Python requests.post使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類requests
的用法示例。
在下文中一共展示了requests.post方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: getTicket
# 需要導入模塊: import requests [as 別名]
# 或者: from requests import post [as 別名]
def getTicket():
# put the ip address or dns of your apic-em controller in this url
url = "https://" + controller + "/api/v1/ticket"
#the username and password to access the APIC-EM Controller
payload = {"username":"usernae","password":"password"}
#Content type must be included in the header
header = {"content-type": "application/json"}
#Performs a POST on the specified url to get the service ticket
response= requests.post(url,data=json.dumps(payload), headers=header, verify=False)
#convert response to json format
r_json=response.json()
#parse the json to get the service ticket
ticket = r_json["response"]["serviceTicket"]
return ticket
開發者ID:PacktPublishing,項目名稱:Mastering-Python-Networking-Second-Edition,代碼行數:22,代碼來源:cisco_apic_em_1.py
示例2: bindiff_export
# 需要導入模塊: import requests [as 別名]
# 或者: from requests import post [as 別名]
def bindiff_export(self, sample, is_64_bit = True, timeout = None):
"""
Load a sample into IDA Pro, perform autoanalysis and export a BinDiff database.
:param sample: The sample's path
:param is_64_bit: If the sample needs to be analyzed by the 64 bit version of IDA
:param timeout: Timeout for the analysis in seconds
:return: The file name of the exported bindiff database. The file needs
to be deleted by the caller. Returns None on error.
"""
data_to_send = {
"timeout": timeout,
"is_64_bit": is_64_bit}
url = "%s/binexport" % next(self._urls)
log.debug("curl -XPOST --data '%s' '%s'", json.dumps(data_to_send), url)
response = requests.post(url, data = data_to_send, files = {os.path.basename(sample): open(sample, "rb")})
if response.status_code == 200:
handle, output = tempfile.mkstemp(suffix = ".BinExport")
with os.fdopen(handle, "wb") as f:
map(f.write, response.iter_content(1024))
return output
else:
log.error("Bindiff server responded with status code %d: %s", response.status_code, response.content)
return None
示例3: pickle_export
# 需要導入模塊: import requests [as 別名]
# 或者: from requests import post [as 別名]
def pickle_export(self, sample, is_64_bit = True, timeout = None):
"""
Load a sample into IDA Pro, perform autoanalysis and export a pickle file.
:param sample: The sample's path
:param is_64_bit: If the sample needs to be analyzed by the 64 bit version of IDA
:param timeout: Timeout for the analysis in seconds
:return: The file name of the exported pickle database. The file needs
to be deleted by the caller. Returns None on error.
"""
data_to_send = {
"timeout": timeout,
"is_64_bit": is_64_bit}
url = "%s/pickle" % next(self._urls)
log.debug("curl -XPOST --data '%s' '%s'", json.dumps(data_to_send), url)
response = requests.post(url, data = data_to_send, files = {os.path.basename(sample): open(sample, "rb")})
if response.status_code == 200:
handle, output = tempfile.mkstemp(suffix = ".pickle")
with os.fdopen(handle, "wb") as f:
map(f.write, response.iter_content(1024))
return output
else:
log.error("Bindiff server responded with status code %d: %s", response.status_code, response.content)
return None
示例4: compare
# 需要導入模塊: import requests [as 別名]
# 或者: from requests import post [as 別名]
def compare(self, primary, secondary, timeout = None):
"""
Run BinDiff on the two BinDiff databases.
:param primary: The first BinExport database
:param secondary: The second BinExport database
:param timeout: Timeout for the command in seconds
:returns: The directory name of the directory with the generated data on the shared volume
"""
url = "%s/compare" % next(self._urls)
log.debug("curl -XPOST --form 'timeout=%s' --form 'primary=@%s' --form 'secondary=@%s' '%s'", str(timeout), primary, secondary, url)
response = requests.post(url, data = {"timeout": timeout}, \
files = {"primary": open(primary, "rb"), "secondary": open(secondary, "rb")})
if response.status_code == 200:
handle, path = tempfile.mkstemp(suffix = ".bindiff.sqlite3")
with os.fdopen(handle, "wb") as f:
map(f.write, response.iter_content(1024))
return path
else:
log.error("Bindiff server responded with status code %d: %s", response.status_code, response.content)
return None
示例5: querylanguage
# 需要導入模塊: import requests [as 別名]
# 或者: from requests import post [as 別名]
def querylanguage(auth):
"""Query user's language that's available on v2c."""
default = 'en'
r = requests.post(
url=api_url.replace('index.php', 'api.php'),
data={
'action': 'query',
'format': 'json',
'meta': 'userinfo',
'uiprop': 'options'
},
auth=auth
)
try:
language = r.json()['query']['userinfo']['options']['language']
except (NameError, KeyError):
return default
if not language:
return default
return language
示例6: post
# 需要導入模塊: import requests [as 別名]
# 或者: from requests import post [as 別名]
def post(self, endpoint, args, data=None, files=None, filename=None,
mode=None):
if mode == 'nojsondumps':
headers = {'Content-type': 'application/x-www-form-urlencoded; charset=utf-8'}
r = requests.post(endpoint, params=args, data=data, headers=headers)
elif files is None:
headers = {'Content-type': 'application/json; charset=utf-8'}
r = requests.post(endpoint, params=args, json=data, headers=headers)
elif files is not None:
mimetype = mimetypes.guess_type(files)[0]
file = {filename: (files, open(files, 'rb'), mimetype)}
r = requests.post(endpoint, params=args, json=data, files=file)
r_json = r.json()
if r_json.get('success'):
return r_json
else:
raise MarketoException(r_json['errors'][0])
示例7: new_post
# 需要導入模塊: import requests [as 別名]
# 或者: from requests import post [as 別名]
def new_post(self, text):
header = {
"Content-Type": "application/json",
"User-Agent" : self.UA,
"X-Line-Mid" : self.mid,
"x-lct" : self.channel_access_token,
}
payload = {
"postInfo" : { "readPermission" : { "type" : "ALL" } },
"sourceType" : "TIMELINE",
"contents" : { "text" : text }
}
r = requests.post(
"http://" + self.host + "/mh/api/v24/post/create.json",
headers = header,
data = json.dumps(payload)
)
return r.json()
示例8: postPhoto
# 需要導入模塊: import requests [as 別名]
# 或者: from requests import post [as 別名]
def postPhoto(self,text,path):
header = {
"Content-Type": "application/json",
"User-Agent" : self.UA,
"X-Line-Mid" : self.mid,
"x-lct" : self.channel_access_token,
}
payload = {
"postInfo" : { "readPermission" : { "type" : "ALL" } },
"sourceType" : "TIMELINE",
"contents" : { "text" : text ,"media" : [{u'objectId': u'F57144CF9ECC4AD2E162E68554D1A8BD1a1ab0t04ff07f6'}]}
}
r = requests.post(
"http://" + self.host + "/mh/api/v24/post/create.json",
headers = header,
data = json.dumps(payload)
)
return r.json()
示例9: like
# 需要導入模塊: import requests [as 別名]
# 或者: from requests import post [as 別名]
def like(self, mid, postid, likeType=1001):
header = {
"Content-Type" : "application/json",
"X-Line-Mid" : self.mid,
"x-lct" : self.channel_access_token,
}
payload = {
"likeType" : likeType,
"activityExternalId" : postid,
"actorId" : mid
}
r = requests.post(
"http://" + self.host + "/mh/api/v23/like/create.json?homeId=" + mid,
headers = header,
data = json.dumps(payload)
)
return r.json()
示例10: comment
# 需要導入模塊: import requests [as 別名]
# 或者: from requests import post [as 別名]
def comment(self, mid, postid, text):
header = {
"Content-Type" : "application/json",
"X-Line-Mid" : self.mid,
"x-lct" : self.channel_access_token,
}
payload = {
"commentText" : text,
"activityExternalId" : postid,
"actorId" : mid
}
r = requests.post(
"http://" + self.host + "/mh/api/v23/comment/create.json?homeId=" + mid,
headers = header,
data = json.dumps(payload)
)
return r.json()
示例11: createAlbum
# 需要導入模塊: import requests [as 別名]
# 或者: from requests import post [as 別名]
def createAlbum(self,gid,name):
header = {
"Content-Type": "application/json",
"User-Agent" : self.UA,
"X-Line-Mid" : self.mid,
"x-lct" : self.channel_access_token,
}
payload = {
"type" : "image",
"title" : name
}
r = requests.post(
"http://" + self.host + "/mh/album/v3/album?count=1&auto=0&homeId=" + gid,
headers = header,
data = json.dumps(payload)
)
return r.json()
示例12: post_image
# 需要導入模塊: import requests [as 別名]
# 或者: from requests import post [as 別名]
def post_image(self):
try:
self.image_b64()
except Exception as e: raise Exception("Image cant be converted.");
payload = "data=data:image/jpeg;base64," + self.b64img
payload += '&filter=*&trial=4'
header = {
'Host':'whatanime.ga',
'accept':'application/json, text/javascript, */*; q=0.01',
'content-type':'application/x-www-form-urlencoded; charset=UTF-8',
'origin':'https://whatanime.ga',
'referer':'https://whatanime.ga/',
'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36',
'x-requested-with':'XMLHttpRequest',
}
r = requests.post('https://whatanime.ga/search', data=payload, headers=header)
if r.status_code == 200:
return r.json()
else:
raise Exception("Post failed.")
示例13: _must_post
# 需要導入模塊: import requests [as 別名]
# 或者: from requests import post [as 別名]
def _must_post(self, api, data=None, json=None, timeout=10, **kwargs):
if data is not None:
kwargs['data'] = data
elif json is not None:
kwargs['json'] = json
else:
kwargs['data'] = {}
kwargs['timeout'] = timeout
try:
r = requests.post(api, **kwargs)
return r
except requests.exceptions.Timeout:
logger.error("Timeout requesting Gitter")
except KeyboardInterrupt:
raise
except:
logger.exception("Unknown error requesting Gitter")
return None
示例14: upload_image
# 需要導入模塊: import requests [as 別名]
# 或者: from requests import post [as 別名]
def upload_image(self, filename=None, filedata=None, **kwargs) -> str:
if filedata is None:
files = {"image": open(filename, 'rb')}
else:
files = {"image": filedata}
try:
r = requests.post(self.url, files=files, timeout=5)
except requests.exceptions.Timeout:
logger.error("Timeout uploading to VimCN")
return None
except:
logger.exception("Unknown errror uploading to VimCN")
return None
if not r.ok:
return None
return r.text.strip()
示例15: comparetext
# 需要導入模塊: import requests [as 別名]
# 或者: from requests import post [as 別名]
def comparetext (text1, text2, api=__ls_api):
"""
Computes the semantic similarity between two given text strings. Returns a score between [-1, 1].
Parameters
----------
text1 : string
text2 : string
api : string (default=cloud release endpoint)
The endpoint you wish to hit for the concept labeling task. Default is the release version of the Microsoft Academic Language Similarity API.
"""
body = {
"Text1": text1,
"Text2": text2
}
endpoint = api + 'comparetext'
resp = requests.post(endpoint, json=body)
assert resp.status_code == 200, endpoint + " failed with status: " + str(resp.status_code)
return float(resp.content)