本文整理汇总了Python中newebe.lib.http_util.ContactClient.post_files方法的典型用法代码示例。如果您正苦于以下问题:Python ContactClient.post_files方法的具体用法?Python ContactClient.post_files怎么用?Python ContactClient.post_files使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类newebe.lib.http_util.ContactClient
的用法示例。
在下文中一共展示了ContactClient.post_files方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_files_to_contact
# 需要导入模块: from newebe.lib.http_util import ContactClient [as 别名]
# 或者: from newebe.lib.http_util.ContactClient import post_files [as 别名]
def send_files_to_contact(self, contact, path, fields, files):
'''
Sends in a form given file and fields to given contact (at given
path).
'''
if not hasattr(self, "activity"):
self.activity = None
client = ContactClient(self.activity)
try:
client.post_files(contact, path, fields=fields, files=files)
except HTTPError:
self.activity.add_error(contact)
self.activity.save()
示例2: send_files_to_contacts
# 需要导入模块: from newebe.lib.http_util import ContactClient [as 别名]
# 或者: from newebe.lib.http_util.ContactClient import post_files [as 别名]
def send_files_to_contacts(self, path, fields, files):
'''
Sends in a form given file and fields to all trusted contacts (at given
path).
If any error occurs, it is stored in linked activity.
'''
contacts = ContactManager.getTrustedContacts()
client = ContactClient(self.activity)
for contact in contacts:
try:
client.post_files(contact, path, fields = fields, files = files)
except HTTPError:
self.activity.add_error(contact)
self.activity.save()
示例3: forward_to_contact
# 需要导入模块: from newebe.lib.http_util import ContactClient [as 别名]
# 或者: from newebe.lib.http_util.ContactClient import post_files [as 别名]
def forward_to_contact(self, picture, contact, activity, method="POST"):
'''
*picture is sent to *contact* via a request of which method is set
as *method*. If request succeeds, error linked to this contact
is removed. Else nothing is done and error code is returned.
'''
client = ContactClient()
try:
if method == "POST":
client.post_files(
contact,
CONTACT_PATH,
{"json": str(picture.toJson(localized=False))},
[("picture",
str(picture.path),
picture.fetch_attachment("th_" + picture.path))
],
callback=(yield gen.Callback("retry"))
)
response = yield gen.Wait("retry")
else:
body = picture.toJson(localized=False)
response = client.put(contact, CONTACT_PATH, body,
callback=(yield gen.Callback("retry")))
response = yield gen.Wait("retry")
if response.error:
message = "Retry picture request to a contact failed ({})."
self.return_failure(message.format(method))
else:
for error in activity.errors:
if error["contactKey"] == contact.key:
activity.errors.remove(error)
activity.save()
self.return_success("Picture request correctly resent.")
except:
self.return_failure("Picture resend to a contact failed again.")