curl-and-python

Check return value of curl.perform()

From: Mohan L <l.mohanphy_at_gmail.com>
Date: Sun, 26 Dec 2010 22:50:23 +0530

Dear All,

I have code like this :

curl = pycurl.Curl()
if not curl:
    print "Could not create Curl handle"
    return

    curl.setopt(pycurl.URL, url)
        curl.setopt(pycurl.NOPROGRESS, True)
        #curl.setopt(pycurl.NOBODY,True)
        curl.setopt(pycurl.POSTFIELDS,login_post)
        curl.setopt(pycurl.SSL_VERIFYPEER, False)
        curl.setopt(pycurl.COOKIEFILE, COOKIE_FILEPATH);
        curl.perform()

        curl.setopt(pycurl.URL,url)
        curl.setopt(pycurl.NOPROGRESS, True)
    #curl.setopt(pycurl.NOBODY,False)
        curl.setopt(pycurl.POSTFIELDS,capacity_post)
        curl.setopt(pycurl.USERAGENT, "...")
        curl.setopt(pycurl.COOKIEJAR, COOKIE_FILEPATH);
        curl.setopt(pycurl.SSL_VERIFYPEER, False)
        f = open(XML_FILEPATH, "w")
        curl.setopt(pycurl.WRITEDATA, f)
        curl.perform()
        curl.close()

1). I am using this code to save cookie information in the file. But it
return the body of request in stdout . I want to stop the body to print
stdout. I tried using curl.setopt(pycurl.NOBODY,True) , it stops printing
the body in stdout but it also stops the body of second curl.perform. I
need suggestion to stop body of response in stdout in the below code.

        curl.setopt(pycurl.URL, url)
        curl.setopt(pycurl.NOPROGRESS, True)
        #curl.setopt(pycurl.NOBODY,True)
        curl.setopt(pycurl.POSTFIELDS,login_post)
        curl.setopt(pycurl.SSL_VERIFYPEER, False)
        curl.setopt(pycurl.COOKIEFILE, COOKIE_FILEPATH);
        curl.perform()

2). How do I check the return value of curl.perform()? How to check and
terminate HTTP Status 401 error?

Thanks & Rg
Mohan L

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-python
Received on 2010-12-26