Custom headers with pycurl

29,268

Solution 1

I would code something like:

pycurl_connect = pycurl.Curl()
pycurl_connect.setopt(pycurl.URL, your_url)
pycurl_connect.setopt(pycurl.HTTPHEADER, ['header_name1: header_value1',
                                          'header_name2: header_value2'])
pycurl_connect.perform()

Solution 2

you can, with HTTPHEADER. just provide your custom headers as a list, like so:

header = ['test: yadayadayada', 'blahblahblah']

curl.setopt(pycurl.HTTPHEADER, header)

Solution 3

Try to use human_curl library https://github.com/Lispython/human_curl

custom_headers = (
('Test-Header', 'fwkjenwkljbnfkjqnewfrjven3lrf'),
('Another-Header', 'ifenwqnfe;wnfqfjlweqnnlf')
)

r = human_curl.get("http://stackoverflow.com",
                    headers=custom_headers)
Share:
29,268

Related videos on Youtube

Pockata
Author by

Pockata

Updated on September 04, 2020

Comments

  • Pockata
    Pockata over 3 years

    Can I send a custom header like "yaddayadda" to the server with the pycurl request?

  • codersofthedark
    codersofthedark over 11 years
    how about multiple headers? Like a list?
  • Gurgeh
    Gurgeh about 7 years
    This does not seem to support Python 3