本文整理汇总了Python中requests.put方法的典型用法代码示例。如果您正苦于以下问题:Python requests.put方法的具体用法?Python requests.put怎么用?Python requests.put使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requests
的用法示例。
在下文中一共展示了requests.put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: changeAlbumName
# 需要导入模块: import requests [as 别名]
# 或者: from requests import put [as 别名]
def changeAlbumName(self,gid,name,albumId):
header = {
"Content-Type" : "application/json",
"X-Line-Mid" : self.mid,
"x-lct": self.channel_access_token,
}
payload = {
"title": name
}
r = requests.put(
"http://" + self.host + "/mh/album/v3/album/" + albumId + "?homeId=" + gid,
headers = header,
data = json.dumps(payload),
)
return r.json()
示例2: run
# 需要导入模块: import requests [as 别名]
# 或者: from requests import put [as 别名]
def run(self):
try:
self.sse = ClosableSSEClient(self.url)
for msg in self.sse:
event = msg.event
if event is not None and event in ('put', 'patch'):
response = json.loads(msg.data)
if response is not None:
# Default to CHILD_CHANGED event
occurred_event = FirebaseEvents.CHILD_CHANGED
if response['data'] is None:
occurred_event = FirebaseEvents.CHILD_DELETED
# Get the event I'm trying to listen to
ev = FirebaseEvents.id(self.event_name)
if occurred_event == ev or ev == FirebaseEvents.CHILD_CHANGED:
self.callback(event, response)
except socket.error:
pass
示例3: keepalive_listen_key
# 需要导入模块: import requests [as 别名]
# 或者: from requests import put [as 别名]
def keepalive_listen_key(self, listen_key):
"""
Ping a listenkey to keep it alive
:param listen_key: the listenkey you want to keepalive
:type listen_key: str
:return: the response
:rtype: str or False
"""
logging.debug("BinanceWebSocketApiRestclient->keepalive_listen_key(" + str(listen_key) + ")")
method = "put"
try:
return self._request(method, self.path_userdata, False, {'listenKey': str(listen_key)})
except KeyError:
return False
except TypeError:
return False
开发者ID:oliver-zehentleitner,项目名称:unicorn-binance-websocket-api,代码行数:20,代码来源:unicorn_binance_websocket_api_restclient.py
示例4: _send_response
# 需要导入模块: import requests [as 别名]
# 或者: from requests import put [as 别名]
def _send_response(self):
"""
Send the response to cloudformation provided url
:return:
"""
# Build the PUT request and the response data
resp = json.dumps(self.response)
headers = {
'content-type': '',
'content-length': str(len(resp))
}
# PUT request to cloudformation provided S3 url
try:
response = requests.put(self.response_url, data=json.dumps(self.response), headers=headers)
response.raise_for_status()
return {"status_code: {}".format(response.status_code),
"status_message: {}".format(response.text)}
except Exception as exc:
raise_exception(ERR_SEND_RESP, self.stack_id, str(exc), self.response_url, resp)
示例5: on_teams_file_consent_accept
# 需要导入模块: import requests [as 别名]
# 或者: from requests import put [as 别名]
def on_teams_file_consent_accept(
self,
turn_context: TurnContext,
file_consent_card_response: FileConsentCardResponse
):
"""
The user accepted the file upload request. Do the actual upload now.
"""
file_path = "files/" + file_consent_card_response.context["filename"]
file_size = os.path.getsize(file_path)
headers = {
"Content-Length": f"\"{file_size}\"",
"Content-Range": f"bytes 0-{file_size-1}/{file_size}"
}
response = requests.put(
file_consent_card_response.upload_info.upload_url, open(file_path, "rb"), headers=headers
)
if response.status_code != 200:
await self._file_upload_failed(turn_context, "Unable to upload file.")
else:
await self._file_upload_complete(turn_context, file_consent_card_response)
示例6: setupDomain
# 需要导入模块: import requests [as 别名]
# 或者: from requests import put [as 别名]
def setupDomain(domain, folder=False):
endpoint = config.get("hsds_endpoint")
headers = getRequestHeaders(domain=domain)
req = endpoint + "/"
rsp = requests.get(req, headers=headers)
if rsp.status_code == 200:
return # already have domain
if rsp.status_code != 404:
# something other than "not found"
raise ValueError(f"Unexpected get domain error: {rsp.status_code}")
parent_domain = getParentDomain(domain)
if parent_domain is None:
raise ValueError(f"Invalid parent domain: {domain}")
# create parent domain if needed
setupDomain(parent_domain, folder=True)
headers = getRequestHeaders(domain=domain)
body=None
if folder:
body = {"folder": True}
rsp = requests.put(req, data=json.dumps(body), headers=headers)
else:
rsp = requests.put(req, headers=headers)
if rsp.status_code != 201:
raise ValueError(f"Unexpected put domain error: {rsp.status_code}")
示例7: testPutInvalid
# 需要导入模块: import requests [as 别名]
# 或者: from requests import put [as 别名]
def testPutInvalid(self):
print("testPutInvalid", self.base_domain)
headers = helper.getRequestHeaders(domain=self.base_domain)
req = self.endpoint + '/'
rsp = requests.get(req, headers=headers)
self.assertEqual(rsp.status_code, 200)
rspJson = json.loads(rsp.text)
root_id = rspJson["root"]
# try creating an attribute with an invalid type
attr_name = "attr1"
attr_payload = {'type': 'H5T_FOOBAR', 'value': 42}
req = self.endpoint + "/groups/" + root_id + "/attributes/" + attr_name
rsp = requests.put(req, data=json.dumps(attr_payload), headers=headers)
self.assertEqual(rsp.status_code, 400) # invalid request
示例8: setupDomain
# 需要导入模块: import requests [as 别名]
# 或者: from requests import put [as 别名]
def setupDomain(domain):
endpoint = config.get("hsds_endpoint")
print("setupdomain: ", domain)
headers = getRequestHeaders(domain=domain)
req = endpoint + "/"
rsp = requests.get(req, headers=headers)
if rsp.status_code == 200:
return # already have domain
if rsp.status_code != 404:
# something other than "not found"
raise ValueError("Unexpected get domain error: {}".format(rsp.status_code))
parent_domain = getParentDomain(domain)
if parent_domain is None:
raise ValueError("Invalid parent domain: {}".format(domain))
# create parent domain if needed
setupDomain(parent_domain)
headers = getRequestHeaders(domain=domain)
rsp = requests.put(req, headers=headers)
if rsp.status_code != 201:
raise ValueError("Unexpected put domain error: {}".format(rsp.status_code))
示例9: _set_status
# 需要导入模块: import requests [as 别名]
# 或者: from requests import put [as 别名]
def _set_status(self, mode, until=None):
# pylint: disable=protected-access
headers = dict(self.client._headers())
headers["Content-Type"] = "application/json"
if until is None:
data = {"SystemMode": mode, "TimeUntil": None, "Permanent": True}
else:
data = {
"SystemMode": mode,
"TimeUntil": until.strftime("%Y-%m-%dT%H:%M:%SZ"),
"Permanent": False,
}
response = requests.put(
"https://tccna.honeywell.com/WebAPI/emea/api/v1"
"/temperatureControlSystem/%s/mode" % self.systemId,
data=json.dumps(data),
headers=headers,
)
response.raise_for_status()
示例10: set_schedule
# 需要导入模块: import requests [as 别名]
# 或者: from requests import put [as 别名]
def set_schedule(self, zone_info):
"""Set the schedule for this zone."""
# must only POST json, otherwise server API handler raises exceptions
# pylint: disable=protected-access
try:
json.loads(zone_info)
except ValueError as error:
raise ValueError("zone_info must be valid JSON: ", error)
headers = dict(self.client._headers())
headers["Content-Type"] = "application/json"
response = requests.put(
"https://tccna.honeywell.com/WebAPI/emea/api/v1/%s/%s/schedule"
% (self.zone_type, self.zoneId),
data=zone_info,
headers=headers,
)
response.raise_for_status()
return response.json()
示例11: _set_heat_setpoint
# 需要导入模块: import requests [as 别名]
# 或者: from requests import put [as 别名]
def _set_heat_setpoint(self, zone, data):
self._populate_full_data()
device_id = self._get_device_id(zone)
url = (
self.hostname
+ "/WebAPI/api/devices/%s/thermostat/changeableValues/heatSetpoint"
% device_id
)
response = self._do_request("put", url, json.dumps(data))
task_id = self._get_task_id(response)
while self._get_task_status(task_id) != "Succeeded":
time.sleep(1)
示例12: test_50_docker_rabbitmq
# 需要导入模块: import requests [as 别名]
# 或者: from requests import put [as 别名]
def test_50_docker_rabbitmq(self):
try:
os.environ['RABBITMQ_NAME'] = 'rabbitmq'
os.environ['RABBITMQ_PORT_5672_TCP_ADDR'] = 'localhost'
os.environ['RABBITMQ_PORT_5672_TCP_PORT'] = '5672'
ctx = run.cli.make_context('test', [], None,
obj=dict(testing_mode=True))
ctx = run.cli.invoke(ctx)
queue = ctx.obj.newtask_queue
queue.put('abc')
queue.delete()
except Exception as e:
self.assertIsNone(e)
finally:
del os.environ['RABBITMQ_NAME']
del os.environ['RABBITMQ_PORT_5672_TCP_ADDR']
del os.environ['RABBITMQ_PORT_5672_TCP_PORT']
示例13: set_settings
# 需要导入模块: import requests [as 别名]
# 或者: from requests import put [as 别名]
def set_settings(self, settings):
h=headers
h.update({
'Authorization' : 'OAuth="'+ self.oauth + '"',
'Content-Length' : '1089', #@TODO figure out length calculation
'Content-Type' : 'application/json'})
# Happn preferences
url = 'https://api.happn.fr/api/users/' + self.id
try:
r = requests.put(url, headers=h, data = json.dumps(settings))
except Exception as e:
raise HTTP_MethodError('Error Setting Settings: {}'.format(e))
if r.status_code == 200: #200 = 'OK'
logging.debug('Updated Settings')
else:
# Unable to fetch distance
raise HTTP_MethodError(httpErrors[r.status_code])
示例14: update_activity
# 需要导入模块: import requests [as 别名]
# 或者: from requests import put [as 别名]
def update_activity(self):
""" Updates User activity """
# Create and send HTTP PUT to Happn server
h = headers
h.update({
'Authorization' : 'OAuth="'+ self.oauth + '"',
'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8',
'Content-Length': '20'
})
payload = {
'update_activity' : 'true'
}
url = 'https://api.happn.fr/api/users/'+self.id
try:
r = requests.put(url, headers=h, data = payload)
except Exception as e:
raise HTTP_MethodError('Error Connecting to Happn Server: {}'.format(e))
if r.status_code == 200: #200 = 'OK'
logging.debug('Updated User activity')
else:
# Unable to fetch distance
raise HTTP_MethodError(httpErrors[r.status_code])
示例15: put
# 需要导入模块: import requests [as 别名]
# 或者: from requests import put [as 别名]
def put(self, *args, **kwargs):
kwargs['method'] = 'put'
return self.do(*args, **kwargs)