本文整理匯總了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.")