Skip to content

Instantly share code, notes, and snippets.

Created May 12, 2022 05:52
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
# -*- coding: utf-8 -*-
# Using curl to get data from
# Template from pycurl documentation
import pycurl #curl library
import certifi #HTTP over TLS/SSL library
from io import BytesIO #Buffered I/O implementation using an in-memory bytes buffer.
#set header, '--header' or -H
header = ['Accept: application/json']
buffer = BytesIO()
c = pycurl.Curl() #curl
c.setopt(c.HTTPHEADER, header) #header
c.setopt(c.URL, '') #URL
c.setopt(c.WRITEDATA, buffer)
c.setopt(c.CAINFO, certifi.where()) # SSL certificates
body = buffer.getvalue()
# Body is a byte string.
# We have to know the encoding in order to print it to a text file
# such as standard output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment