0

I've read a lot about multipart/forms, mechanize and twill, but I couldn' findout howto implement a code.

Using MultipartPostHandler to POST form-data with Python

First I Tried to fill the forms on

www.imagebam.com/basic-upload

I can fill the forms but cant send the data really even if I submit() it.

after looking the source code at the page above, I realized all I need to do is "post" data in correct content-type to the page (correct me if Im wrong please)

http://www.imagebam.com/sys/upload/save

directly..

I tried to use poster.py, but couldnt understand how this stuff works. I can use mechanize and twill a little bit, but I am stucked since this is more complex than simple form posting, I think.

So my questions;

-How can I use poster.py (or user-created multipartform classes) to upload images to imagebam.com

-or any other alternative solutions :)

Community
  • 1
  • 1
gokcennurlu
  • 33
  • 1
  • 6

3 Answers3

0

Mechanize is not the right tool for the task.

Implementing http://code.google.com/p/imagebam-api/ in python is way more robust.

The examples are in PHP/curl, converting them to python/urllib2 should be trivial.

Paulo Scardine
  • 73,447
  • 11
  • 124
  • 153
  • thank you for comment :) I solved it by using http://stackoverflow.com/questions/6850239/trying-to-post-multipart-form-data-in-python-wont-post poster module :) – gokcennurlu Jan 14 '12 at 15:17
0

Don't rely completely on third party libraries like mechanize. Either implement its official api in python API ImageBam or see this project developed in pyqt4 pymguploader to upload image and than try to implement yourself.

RanRag
  • 48,359
  • 38
  • 114
  • 167
  • thank you for comment :) I found imageban api hard to understand cuz I dont know anything about "oatuh" stuff. I solved problem by using poster.py :) – gokcennurlu Jan 14 '12 at 15:21
0

Yes! I did it. I used this question.

Here is the code:

>>> from poster.encode import multipart_encode
>>> from poster.streaminghttp import register_openers
>>> import urllib2
>>> register_openers()
<urllib2.OpenerDirector instance at 0x02CDD828>
>>> datagen, headers = multipart_encode({"file[]": open("D:\hedef\myfile.jpg","rb"),"content_type":"1","thumb_size":"350"})
>>> request = urllib2.Request("http://www.imagebam.com/sys/upload/save", datagen, headers)
>>> print urllib2.urlopen(request).read()

Now all I need to do is use BeautifulSoup to fecth the thumbnail codes :)

Community
  • 1
  • 1
gokcennurlu
  • 33
  • 1
  • 6