【问题标题】:Error with pycurl when sending a GET request (1010)发送 GET 请求时 pycurl 出错 (1010)
【发布时间】:2023-01-14 23:07:10
【问题描述】:

我想使用 pycurl 向 FTX Exchange 发送请求。 我试过

import pycurl
import certifi
from io import BytesIO

buffer = BytesIO()
c = pycurl.Curl()
c.setopt(c.URL, 'https://ftx.com/api')
c.setopt(c.WRITEDATA, buffer)
c.setopt(c.CAINFO, certifi.where())
c.perform()
c.close()

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

但我得到一个错误

error code: 1010

有谁知道这个错误是从哪里来的?我想这与我用c.setopt(c.CAINFO, certifi.where())设置的证书包有关

【问题讨论】:

    标签: python request pycurl


    【解决方案1】:

    网站似乎使用像 Cloudflare 这样的 Web 应用程序防火墙“WAF”,您需要将 User-Agent Header 添加到您的代码中,一切正常,我在许多网站上进行了测试

    custom_headers = ['User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0/8mqLkJuL-86']
    
    c.setopt(pycurl.HTTPHEADER, custom_headers)
    

    【讨论】: