1

I already checked a lot of code snippets but i could not get how to post multipart both text and binary files in single request with only python 2.4? Here in comments mentioned something about BytesIO class but is not present in 2.4. (plain python, no third-party libraries) Thanks.

2
  • 1
    Have you looked at poster?
    – jterrace
    Jan 25, 2012 at 23:17
  • If there is no way to do this without third-party, i will try to dig into poster sources. But i hope there is some kind of workaround.
    – Oink
    Jan 26, 2012 at 9:25

1 Answer 1

0

with Python 2.6 you can use requests library, here is snippet extracted from the documentation:

>>> url = 'http://httpbin.org/post'
>>> files = {'report.xls': open('report.xls', 'rb')}

>>> r = requests.post(url, files=files)
>>> r.text
{
  "origin": "179.13.100.4",
  "files": {
    "report.xls": "<censored...binary...data>"
  },
  "form": {},
  "url": "http://httpbin.org/post",
  "args": {},
  "headers": {
    "Content-Length": "3196",
    "Accept-Encoding": "identity, deflate, compress, gzip",
    "Accept": "*/*",
    "User-Agent": "python-requests/0.8.0",
    "Host": "httpbin.org:80",
    "Content-Type": "multipart/form-data; boundary=127.0.0.1.502.21746.1321131593.786.1"
  },
  "data": ""
}
1
  • I'm not sure if any version of requests supports Python 2.4.
    – Thomas K
    Jan 25, 2012 at 21:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.