*Date:* 27 Jun 2022

*Module:* pycurl


*Installation:* pip install pycurl


*About:*

PycURL is a Python interface to libcurl, the multiprotocol FILE, FTPS,
HTTP, HTTPS, IMAP, POP3, SMTP, SCP, SMB, etc. file transfer library. PycURL
module can be used to fetch objects with high speed from a URL.


*Sample:*

import pycurl

from io import BytesIO


b_obj = BytesIO()

crl = pycurl.Curl()


# Set URL value

crl.setopt(crl.URL, 'https://wiki.python.org/moin/BeginnersGuide')


# Write bytes that are utf-8 encoded

crl.setopt(crl.WRITEDATA, b_obj)


# Perform a file transfer

crl.perform()


# End curl session

crl.close()


# Get the content stored in the BytesIO object (in byte characters)

get_body = b_obj.getvalue()


# Decode the bytes stored in get_body to HTML and print the result

print('Output of GET request:\n%s' % get_body.decode('utf8'))


*Execution:*

% % python pycurl_sample.py


*Output:*

Output of GET request:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "
http://www.w3.org/TR/html4/strict.dtd";>

<html>

.. < wiki page content > ..

</html>


*Reference:*

https://pypi.org/project/pycurl/

https://stackabuse.com/using-curl-in-python-with-pycurl/
_______________________________________________
Chennaipy mailing list
Chennaipy@python.org
https://mail.python.org/mailman/listinfo/chennaipy

Reply via email to