从PHP到python请求库的CURL头文件?

时间:2017-04-11 02:15:17

标签: php python curl

我目前正在从PHP翻译代码:

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_DNS_CACHE_TIMEOUT, 120);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
    curl_setopt($ch, CURLOPT_TIMEOUT, 5);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TCP_NODELAY, 1);
    curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); 

如何在python的请求中设置这些变量?

这是我到目前为止所拥有的

output = requests.post(url,headers = headers)

1 个答案:

答案 0 :(得分:0)

你必须做这样的事情:

c = pycurl.Curl()

c.setopt(c.URL, url)
c.setopt(c.WRITEFUNCTION, buffer.write)
c.setopt(c.USERPWD,USER+':'+PASSWORD)
c.setopt(c.VERBOSE, True)
c.setopt(c.HEADERFUNCTION, header_function)
c.perform()