【发布时间】:2012-08-03 16:21:07
【问题描述】:
我正在尝试使用 requests 模块重写一些旧的 python 代码。 目的是上传附件。 邮件服务器需要以下规范:
https://api.elasticemail.com/attachments/upload?username=yourusername&api_key=yourapikey&file=yourfilename
有效的旧代码:
h = httplib2.Http()
resp, content = h.request('https://api.elasticemail.com/attachments/upload?username=omer&api_key=b01ad0ce&file=tmp.txt',
"PUT", body=file(filepath).read(),
headers={'content-type':'text/plain'} )
没有找到如何在请求中使用正文部分。
我设法做到了以下几点:
response = requests.put('https://api.elasticemail.com/attachments/upload',
data={"file":filepath},
auth=('omer', 'b01ad0ce')
)
但不知道如何用文件内容指定正文部分。
感谢您的帮助。 奥马尔。
【问题讨论】:
标签: python http put httplib2 python-requests