Curl Object

class pycurl.Curl

Curl() -> New Curl object

Creates a new Curl Object which corresponds to a CURL handle in libcurl. Curl objects automatically set CURLOPT_VERBOSE to 0, CURLOPT_NOPROGRESS to 1, provide a default CURLOPT_USERAGENT and setup CURLOPT_ERRORBUFFER to point to a private error buffer.

Implicitly calls global_init() if the latter has not yet been called.

Curl objects have the following methods:

close() → None

Corresponds to curl_easy_cleanup in libcurl. This method is automatically called by pycurl when a Curl object no longer has any references to it, but can also be called explicitly.

perform() → None

Corresponds to curl_easy_perform in libcurl.

reset() → None

Corresponds to curl_easy_reset in libcurl.

setopt(option, value) → None

Corresponds to curl_easy_setopt in libcurl, where option is specified with the CURLOPT_* constants in libcurl, except that the CURLOPT_ prefix has been removed. (See below for exceptions.) The type for value depends on the option, and can be either a string, integer, long integer, file object, list, or function.

Example usage:

import pycurl
c = pycurl.Curl()
c.setopt(pycurl.URL, "")
c.setopt(pycurl.HTTPHEADER, ["Accept:"])
import StringIO
b = StringIO.StringIO()
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.setopt(pycurl.FOLLOWLOCATION, 1)
c.setopt(pycurl.MAXREDIRS, 5)
print b.getvalue()
getinfo(option) → Result

Corresponds to curl_easy_getinfo in libcurl, where option is the same as the CURLINFO_* constants in libcurl, except that the CURLINFO_ prefix has been removed. (See below for exceptions.) Result contains an integer, float or string, depending on which option is given. The getinfo method should not be called unless perform has been called and finished.

Example usage:

import pycurl
c = pycurl.Curl()
c.setopt(pycurl.URL, "")
c.setopt(pycurl.FOLLOWLOCATION, 1)
print c.getinfo(pycurl.HTTP_CODE), c.getinfo(pycurl.EFFECTIVE_URL)
--> 200 ""
pause(bitmask) → None

Corresponds to curl_easy_pause in libcurl. The argument should be derived from the PAUSE_RECV, PAUSE_SEND, PAUSE_ALL and PAUSE_CONT constants.

errstr() → string

Returns the internal libcurl error buffer of this handle as a string.

In order to distinguish between similarly-named CURLOPT and CURLINFO constants, some have OPT_ and INFO_ prefixes. These are INFO_FILETIME, OPT_FILETIME, INFO_COOKIELIST (but setopt uses COOKIELIST!), INFO_CERTINFO, and OPT_CERTINFO.

The value returned by getinfo(INFO_CERTINFO) is a list with one element per certificate in the chain, starting with the leaf; each element is a sequence of (key, value) tuples.

Previous topic

pycurl Module Functionality

Next topic

CurlMulti Object

This Page