Package: pycurl-requests
PycURL Requests<pycurl://☤>PycURL Requestsis aRequests-compatible interface forPycURL.RequirementsPython 3.6+PycURLchardetInstallationLatest release viapip:pipinstallpycurl-requests[--user]via Git:gitclonehttps://github.com/dcoles/pycurl-requests.git;cdpycurl-requests
python3setup.pyinstall[--user]Quick-start>>>importpycurl_requestsasrequests>>>r=requests.get('https://api.github.com/repos/dcoles/pycurl-requests')>>>r.status_code200>>>r.headers['content-type']'application/json; charset=utf-8'>>>r.encoding'utf-8'>>>r.text'{\n"id": 236427187,\n...'>>>data=r.json()>>>data['name']'pycurl-requests'>>>data['html_url']'https://github.com/dcoles/pycurl-requests'>>>data['description']'A Requests-compatible interface for pycURL'The library can also be used to run existing Python scripts that import therequestsmodule.
By running the script through thepycurl_requestshelper, any use of therequestsmodule will
be automatically redirected topycurl_requests.python3-mpycurl_requests--script.pyargarg...requesttoolA basiccurl-like command-line utility is included:usage: request.py [-h] [-d DATA] [-H HEADER] [--json JSON] [-L] [-o OUTPUT]
                  [-X REQUEST] [-v]
                  url

A basic `curl`-like command-line HTTP utility

positional arguments:
  url                   URL of resource to connect to

optional arguments:
  -h, --help            show this help message and exit
  -d DATA, --data DATA  Add POST data
  -H HEADER, --header HEADER
                        Add custom request header (format: `Header: Value`)
  --json JSON           Add JSON POST data
  -L, --location        Follow redirects
  -o OUTPUT, --output OUTPUT
                        Write to file instead of stdout
  -X REQUEST, --request REQUEST
                        Request command to use (e.g. HTTP method)
  -v, --verbose         Verbose loggingThis can also be used with theRequestslibrary ifPYCURLREQUESTS_REQUESTSenvironment variable is set to a non-null value.DocumentationThis library aims to be API compatible withRequests,
thus theRequests documentationshould be
mostly applicable.AdaptersPycURL support is implemented as atransport adapter.
This means it's possible to use PycURL with the Requests library itself!importpycurlimportrequestsfrompycurl_requests.adaptersimportPyCurlHttpAdapterwithrequests.Session()assession:curl=pycurl.Curl()session.mount('https://',PyCurlHttpAdapter(curl))session.mount('http://',PyCurlHttpAdapter(curl))response=session.get('http://example.com')cURL optionsIt is possible customize cURL's behaviour using thecurlattribute on aSession object.For example, to make a request without requesting the body:importpycurlimportpycurl_requestsasrequestswithrequests.Session()assession:session.curl.setopt(pycurl.NOBODY,1)response=session.get('http://example.com')See thepycurl.Curlobjectdocumentation
for all possiblecurlattribute methods.cURL exceptionsAllpycurl.errorexceptionsare mapped to arequests.RequestException(or one of its subclasses).For convenience, the originalpycurl.errorerror message andcURL error codewill be set on the exception
object as thecurl_messageandcurl_codeattributes.importpycurl_requestsasrequeststry:requests.get('http://connect_error')exceptrequests.RequestExceptionase:print('ERROR:{}(cURL error:{})'.format(e.curl_message,e.curl_code))It is also possible to obtain the originalpycurl.errorusing the__cause__attribute.LoggingDetailed log records fromlibcurl, including informational text and HTTP headers, can be shown
by setting thecurllogger (or sub-loggers) toDEBUGlevel:importlogginglogging.getLogger('curl').setLevel(logging.DEBUG)Log records are split into dedicated sub-loggers for each type of record:curl.text— Informational textcurl.header_in— Header data received from the peercurl.header_out— Header data sent to the peerKnown limitationsNo support for readingCookiesNo support forclient-side certificatesNo support forproxiesNo support forlink headers(e.g.Response.links)No support forsending multi-part encoded filesBasic support forSessionobjects(e.g.requests.Session)LicenseLicensed under the MIT License.