Can I send a custom header like "yaddayadda" to the server with the pycurl request?
Asked
Active
Viewed 3.2k times
3 Answers
54
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()

systempuntoout
- 71,966
- 47
- 171
- 241
-
how about multiple headers? Like a list? – codersofthedark Sep 04 '12 at 07:03
-
why a pseudo-dictionary instead of a real dictionary? ['key: val', 'key: val'] vs {'key': 'val', 'key': 'val'}... – JayRugMan Jul 05 '23 at 15:30
6
you can, with HTTPHEADER. just provide your custom headers as a list, like so:
header = ['test: yadayadayada', 'blahblahblah']
curl.setopt(pycurl.HTTPHEADER, header)

maranas
- 1,396
- 1
- 12
- 21
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)

Alexandr
- 381
- 1
- 5
- 13