如何添加 Pycurl headers

How to add Pycurl headers

我无法理解这个作品 如何将多个 headers 添加到 pycurl HTTPS 请求, 我尝试这样做,但它只接受用户代理,如果我尝试添加更多 headers

,它会给我一个错误
url = "https://blabla.com"
buffer = BytesIO()
c = pycurl.Curl()
c.setopt(pycurl.CAINFO, certifi.where())
c.setopt(c.URL, url)
c.setopt(pycurl.SSL_VERIFYPEER, 0)
c.setopt(pycurl.SSL_VERIFYHOST, 0)
c.setopt(pycurl.HTTPHEADER, custom_headers)
c.setopt(c.WRITEDATA, buffer)
c.setopt(c.FOLLOWLOCATION, True)
c.perform()
c.close()
body = buffer.getvalue()
response = body.decode("utf-8")
print (response)

是否必须将 headers 设置为列表

custom_headers = ['example1: ex1', 'example2: ex2']
curl.setopt(pycurl.HTTPHEADER, custom_headers)

来自 http://pycurl.io/docs/latest/curlobject.html?highlight=httpheader

的 pycurl 文档

HTTP200ALIASESHTTPHEADERPOSTQUOTEPREQUOTEPROXYHEADERQUOTE 接受字符串列表或元组。适用于这些字符串的规则与适用于字符串选项值的规则相同。示例:

c.setopt(pycurl.HTTPHEADER, ["Accept:"])
c.setopt(pycurl.HTTPHEADER, ("Accept:",))