Bootstrap FreeKB - Python (Scripting) - GET request using pycurl
Python (Scripting) - GET request using pycurl

Updated:   |  Python (Scripting) articles

Almost always, the requests module is be used to issue a REST API request.

However, if for whatever reason requests cannot be used, pycurl can get used.

You will probably need to use pip to install the pycurl module.

pip install pycurl

 

And here is an example of how to submit a GET request to www.example.com and to display the response data.

#!/usr/bin/python3
import pycurl
import certifi
from io import BytesIO

buffer = BytesIO()
c = pycurl.Curl()
c.setopt(c.URL, 'http://www.example.com/')
c.setopt(c.WRITEDATA, buffer)
c.setopt(c.CAINFO, certifi.where())
c.perform()
c.close()

body = buffer.getvalue()
print(body.decode('iso-8859-1'))

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 138958 in the box below so that we can be sure you are a human.