本文整理汇总了Python中multipart.post_multipart函数的典型用法代码示例。如果您正苦于以下问题:Python post_multipart函数的具体用法?Python post_multipart怎么用?Python post_multipart使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了post_multipart函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: httpPOST
def httpPOST(self, url):
# Increment request counter
self.postReqs += 1
"""
Post fields and files to an http host as multipart/form-data.
fields is a sequence of (name, value) elements for regular form fields.
files is a sequence of (name, filename, value) elements for data to be uploaded as files
Return the server's response page.
"""
now = datetime.datetime.now() # Current timestamp
fields = []
fields.append(('video[name]', 'NewHTTPClient uploading ELL_PART_5_768k.wmv'))
fields.append(('video[author]', 'NewHTTPClient'))
# Get current timestamp - set as description
now = datetime.datetime.now()
fields.append(('video[description] Upload occured at ', str(now)))
# Read file
f = open('ELL_PART_5_768k.wmv', 'r')
data = f.read()
f.close()
self.txBytes += len(data)
file = ('video[movie]', 'ELL_PART_5_768k.wmv', data)
files = []
files.append(file)
host = url
selector = {}
post_multipart(host, selector, fields, files)
示例2: _postSS
def _postSS(screenshot):
fileName = time.strftime('ss (%Y-%m-%d at %H.%M.%S).' + FORMAT)
# split the apiKey for the basicAuth
config.apiKey = config.apiKey.lower()
l = int(len(config.apiKey)/2)
basicAuth = (config.apiKey[:l], config.apiKey[l:])
# save file into buf
picBuf = StringIO.StringIO()
screenshot.save_to_callback(_saveToBuf, FORMAT, {}, {'buf' :picBuf})
# build file list
fileList = [('media', fileName, picBuf.getvalue())]
if NO_INTERNET:
link = "<mediaurl>http://puu.sh/2ES4oa.png</mediaurl>"
else:
link = multipart.post_multipart(SERVER, API_END_POINT, files=fileList, basicAuth=basicAuth)
print link
# link looks like "<mediaurl>http://puu.sh/2ES4o.png</mediaurl>"
# strip open and close tags
_notify(link[10:len(link) - 11])
示例3: reply
def reply(msg=None, img=None, aux=None, esp=None):
resp = None
if msg:
resp = urllib2.urlopen(BASE_URL + 'sendMessage', urllib.urlencode({
'chat_id': str(chat_id),
'text': msg,
})).read()
elif img:
resp = multipart.post_multipart(BASE_URL + 'sendPhoto', [
('chat_id', str(chat_id)),
('reply_to_message_id', str(message_id)),
], [
('photo', 'image.jpg', img),
])
elif aux:
resp = urllib2.urlopen(BASE_URL + 'sendMessage', urllib.urlencode({
'chat_id': str(aux),
'text': 'Olá jogadores do focar_bot, estivemos passando por alguns problemas na última hora como alguns devem ter percebido. Caso não estejam conseguindo jogar, recomendamos que cancelem o jogo atual e começem um novo. Caso ainda assim não estejam conseguindo jogar, contate @cristoferoswald ou @bcesarg6. Desculpem o inconveniente.'
#'text':'\t'+emoji_gritar+'***AVISO***'+emoji_gritar+'\nJogadores do forca_bot, uma nova versão do bot foi lançada! A versão 2.0 traz muitas novidades e uma interface totalmente nova. Recomendamos que você passe a utilizar o novo bot. Basta clicar em @PlayHangmanBot. Informamos que essa versão do bot não receberá mais atualizações e eventualmente será desligada, portanto utilizem o novo. Avisem seus amigos e se divirtam!',
#'disable_web_page_preview': 'true',
#'reply_to_message_id': str(message_id),
})).read()
elif esp:
resp = urllib2.urlopen(BASE_URL + 'sendMessage', urllib.urlencode({
'chat_id': str(-34151177),
'text': 'Novo chat criado',
#'disable_web_page_preview': 'true',
#'reply_to_message_id': str(message_id),
})).read()
else:
logging.error('no msg or img specified')
resp = None
logging.info('send response:')
logging.info(resp)
示例4: reply
def reply(msg=None, img=None, parsemode=None, markup=None):
if msg:
if markup:
markup = markup
else:
markup = { 'hide_keyboard' : True }
resp = urllib2.urlopen(BASE_URL + 'sendMessage', urllib.urlencode({
'chat_id': str(chat_id),
'text': msg.encode('utf-8'),
'disable_web_page_preview': 'true',
'parse_mode' : "Markdown", # str(parsemode),
'reply_markup' : json.dumps(markup)
})).read()
elif img:
resp = multipart.post_multipart(BASE_URL + 'sendPhoto', [
('chat_id', str(chat_id)),
], [
('photo', 'image.jpg', img),
])
else:
logging.error('No message or image specified.')
resp = None
logging.info('Send response:')
logging.info(resp)
示例5: reply
def reply(msg=None, img=None):
if msg:
try:
encoded_msg = msg.encode('utf-8')
except UnicodeEncodeError:
encoded_msg = unicode(msg, 'utf-8').encode('utf-8')
resp = urllib2.urlopen(BASE_URL + 'sendMessage', urllib.urlencode({
'chat_id': str(chat_id),
'text': encoded_msg,
'disable_web_page_preview': 'true',
'reply_to_message_id': str(message_id),
})).read()
elif img:
resp = multipart.post_multipart(BASE_URL + 'sendPhoto', [
('chat_id', str(chat_id)),
('reply_to_message_id', str(message_id)),
], [
('photo', 'image.jpg', img),
])
else:
logging.error('no msg or img specified')
resp = None
logging.info('send response:')
logging.info(resp)
示例6: reply
def reply(msg=None, img=None):
if msg:
resp = urllib2.urlopen(
BASE_URL + "sendMessage",
urllib.urlencode(
{
"chat_id": str(chat_id),
"text": msg.encode("utf-8"),
"disable_web_page_preview": "true",
"reply_to_message_id": str(message_id),
}
),
).read()
elif img:
resp = multipart.post_multipart(
BASE_URL + "sendPhoto",
[("chat_id", str(chat_id)), ("reply_to_message_id", str(message_id))],
[("photo", "image.jpg", img)],
)
else:
logging.error("no msg or img specified")
resp = None
logging.info("send response:")
logging.info(resp)
示例7: reply
def reply(msg=None, img=None, audio=None, document=None, location=None):
if msg:
resp = urllib2.urlopen(BASE_URL + 'sendMessage', urllib.urlencode({
'chat_id': str(chat_id),
'text': msg.encode('utf-8'),
'disable_web_page_preview': 'true',
'reply_to_message_id': str(message_id),
})).read()
elif img:
resp = multipart.post_multipart(BASE_URL + 'sendPhoto', [
('chat_id', str(chat_id)),
('reply_to_message_id', str(message_id)),
], [
('photo', 'image.jpg', img),
])
elif audio:
resp = multipart.post_multipart(BASE_URL + 'sendAudio', [
('chat_id', str(chat_id)),
('reply_to_message_id', str(message_id)),
], [
('audio', 'audio.mp3', audio),
])
elif document:
resp = multipart.post_multipart(BASE_URL + 'sendDocument', [
('chat_id', str(chat_id)),
('reply_to_message_id', str(message_id)),
], [
('document', 'document.pdf', document),
])
elif location:
resp = urllib2.urlopen(BASE_URL + 'sendLocation', urllib.urlencode({
'chat_id': str(chat_id),
'latitude': location[0],
'longitude': location[1],
'reply_to_message_id': str(message_id),
})).read()
else:
logging.error('no msg or action specified')
resp = None
logging.info('send response:')
logging.info(resp)
示例8: reply
def reply(self, chat_id, message=None, photo=None, document=None, gif=None,
location=None, preview_disabled=True, caption=None):
if message:
response = urllib2.urlopen(self.base_url + 'sendMessage',
urllib.urlencode({
'chat_id': str(chat_id),
'text': message.encode('utf-8'),
'disable_web_page_preview':
str(preview_disabled)
})).read()
self.log('Bot sent reply "' + message + '" to ' +
str(chat_id) + '.')
elif photo:
self.send_action(chat_id, 'upload_photo')
parameters = [('chat_id', str(chat_id))]
reply_markup = ({
'hide_keyboard': True
})
reply_markup = json.dumps(reply_markup)
parameters.append(('reply_markup', reply_markup))
if caption:
parameters.append(('caption', caption.encode('utf-8')))
response = post_multipart(self.base_url + 'sendPhoto', parameters,
[('photo', 'photo.jpg', photo)])
self.log('Bot sent photo to ' + str(chat_id) + ' with caption: ' + caption)
elif gif or document:
file_name = 'image.gif' if gif else 'document.file'
self.send_action(chat_id, 'upload_document')
response = post_multipart(self.base_url + 'sendDocument',
[('chat_id', str(chat_id))],
[('document', (file_name),
(gif if gif else document))])
self.log('Bot sent document to ' + str(chat_id) + '.')
elif location:
response = urllib2.urlopen(self.base_url + 'sendLocation',
urllib.urlencode({
'chat_id': str(chat_id),
'latitude': location[0],
'longitude': location[1]
})).read()
self.log('Bot sent location to ' + str(chat_id) + '.')
示例9: wrapper
def wrapper(self):
client = Client(Application(), BaseResponse)
response = client.get(url, headers={'Accept': accept})
eq_(response.status_code, status_code)
if template:
assert response.template ==template
f(self, response, response.context, PyQuery(response.data))
# Validate after other tests so we know everything else works.
# Hacky piggybacking on --verbose so tests go faster.
if '--verbose' in sys.argv:
validator = post_multipart('validator.w3.org', '/check',
{'fragment': response.data})
assert PyQuery(validator)('#congrats').size() == 1
示例10: _invoke
def _invoke(service, opts, pdb):
import multipart
try:
return multipart.post_multipart(
"helixweb.nih.gov",
"/cgi-bin/structbio/basic",
opts + [
( "pdb_file", "chimera", pdb ),
( "what", None, service ),
( "outputtype", None, "Raw" ),
]
)
except:
raise chimera.NonChimeraError("Error contacting "
"StrucTools web server")
示例11: reply
def reply(msg=None, img=None, stk=None, audio=None, doc=None, fw=None, chat=None):
if msg:
resp = urllib2.urlopen(BASE_URL + 'sendMessage', urllib.urlencode({
'chat_id': str(chat_id),
'text': msg,
'disable_web_page_preview': 'true',
})).read()
elif img:
resp = multipart.post_multipart(BASE_URL + 'sendPhoto', [
('chat_id', str(chat_id)),
], [
('photo', 'image.jpg', img),
])
elif stk:
resp = urllib2.urlopen(BASE_URL + 'sendSticker', urllib.urlencode({
'chat_id': str(chat_id),
'sticker': stk,
})).read()
elif audio:
resp = urllib2.urlopen(BASE_URL + 'sendAudio', urllib.urlencode({
'chat_id': str(chat_id),
'audio': audio,
})).read()
elif doc:
resp = urllib2.urlopen(BASE_URL + 'sendDocument', urllib.urlencode({
'chat_id': str(chat_id),
'document': doc,
})).read()
elif fw:
resp = urllib2.urlopen(BASE_URL + 'forwardMessage', urllib.urlencode({
'chat_id': fw,
'from_chat_id': str(chat_id),
'message_id': str(message_id),
})).read()
elif chat:
resp = urllib2.urlopen(BASE_URL + 'sendMessage', urllib.urlencode({
'chat_id': 'target_chat_id',
'text': chat.replace("=SEND=", "").encode('utf-8'),
'disable_web_page_preview': 'true',
})).read()
else:
logging.error('no msg or img specified')
resp = None
logging.info('send response:')
logging.info(resp)
示例12: reply
def reply(msg=None, img=None):
if msg:
resp = urllib2.urlopen(BASE_URL + 'sendMessage', urllib.urlencode({
'chat_id': str(chat_id),
'text': msg.encode('utf-8'),
'disable_web_page_preview': 'true',
})).read()
elif img:
resp = multipart.post_multipart(BASE_URL + 'sendPhoto', [
('chat_id', str(chat_id)),
], [
('photo', 'image.jpg', img),
])
else:
logging.error('No message or image specified.')
resp = None
logging.info('Send response:')
logging.info(resp)
示例13: send_message
def send_message(msg=None, img=None): # exactly the same as reply() but no reply_to_message_id parameter
if msg:
resp = urllib2.urlopen(BASE_URL + "sendMessage", urllib.urlencode({
"chat_id": str(chat_id),
"text": msg.encode("utf-8"),
"parse_mode": "Markdown",
"disable_web_page_preview": "true",
})).read()
elif img:
resp = multipart.post_multipart(BASE_URL + "sendPhoto", [
("chat_id", str(chat_id)),
], [
("photo", "image.jpg", img),
])
else:
logging.error("no msg or img specified")
resp = None
logging.info("send response: " + str(resp))
示例14: _postSS
def _postSS(screenshot):
fileName = time.strftime('ss (%Y-%m-%d at %H.%M.%S).' + FORMAT)
# save file into buf
picBuf = StringIO.StringIO()
screenshot.save_to_callback(_saveToBuf, FORMAT, {}, {'buf' :picBuf})
# build file list
fileList = [('files[]', fileName, picBuf.getvalue())]
if NO_INTERNET:
link = "NO INTERNET"
else:
response = multipart.post_multipart(SERVER, API_END_POINT, files=fileList)
try:
data = json.loads(response)
link = data["direct"]
_notify("La imagen se ha subido correctamente", link)
except ValueError:
_notify("Error","Error al subir la imagen")
示例15: send_message_html
def send_message_html(msg=None, img=None):
# exactly the same as reply() but no reply_to_message_id parameter
if msg:
resp = urllib2.urlopen(BASE_URL + 'sendMessage', urllib.urlencode({
'chat_id': str(chat_id),
'text': msg.encode('utf-8'),
'parse_mode': 'HTML',
'disable_web_page_preview': 'true',
})).read()
elif img:
resp = multipart.post_multipart(BASE_URL + 'sendPhoto', [
('chat_id', str(chat_id)),
], [
('photo', 'image.jpg', img),
])
else:
logging.error('no msg or img specified')
resp = None
logging.info('send response: ' + str(resp))