curl-and-python
Re: Is there a way to use form_stream in pycurl?
Date: Tue, 9 Sep 2014 08:41:28 -0300
In my case i had to zip a file before sending it, so i was worried about
having to open the file, zip the content, write a new file and send it, so
i did something like this:
So, the relevant parts of my code (showing the use and some useful stuff
alltogether):
-----------------------------------------------------------------
import pycurl
import gzip
from StringIO import StringIO as sio
c = pycurl.Curl()
with open('teste.xml', 'r') as xml_file:
xml_content = xml_file.read()
ziped = sio()
with gzip.GzipFile(fileobj=ziped, mode='w') as f:
f.write(xml_content)
run_data = ziped.getvalue()
data = [..... ('file_to_upload', (c.FORM_BUFFER, 'upate_config',
c.FORM_BUFFERPTR, run_data))]
c.setopt(c.HTTPPOST, data)
c.perform()
c.close()
----------------------------------------------------------------------
Hope it helps someone : )
On Tue, Sep 9, 2014 at 4:38 AM, Dima Tisnek <dimaqq_at_gmail.com> wrote:
> Please contribute sample code, current test case is way too terse!
>
> On 8 September 2014 23:05, Tonhão - Antonio Brasolin
> <tonhoanhon_at_gmail.com> wrote:
> > Oh, it worked fine! I had an old version of pycurl so I didn't have this
> > function.
> >
> > Updated -> tried -> worked.
> >
> > Thanks for the help! : )
> >
> > On Sat, Sep 6, 2014 at 12:34 AM, Oleg Pudeyev <oleg+pycurl_at_bsdpower.com>
> > wrote:
> >>
> >> On Fri, 5 Sep 2014 14:04:21 -0300
> >> Tonhão - Antonio Brasolin <tonhoanhon_at_gmail.com> wrote:
> >>
> >> > So my doubt is: is there an alternative to pycurl.FORM_FILE that takes
> >> > either a string to be sent or a stream object (like a file object)?
> >>
> >> pycurl.FORM_BUFFERPTR sounds like what you are looking for.
> >>
> >> https://github.com/pycurl/pycurl/blob/master/tests/post_test.py#L102
> >>
> >> Oleg
> >
> >
> >
> >
> > --
> > El Psy Congroo,
> > Antonio Añon Brasolin,
> > Masters Degree Student in Universidade Federal de São Carlos
> >
> > _______________________________________________
> > http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
> >
>
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
>
-- El Psy Congroo, Antonio Añon Brasolin, Masters Degree Student in Universidade Federal de São Carlos
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
Received on 2014-09-09