将请求请求转换为pycurl请求

时间:2018-07-25 07:31:13

标签: python curl python-requests pycurl

如何将下面的requests请求转换为PyCurl请求?

import requests

http_proxy  = 'some_proxy1'
https_proxy = 'some_proxy2'
proxyDict = { 
              "http"  : http_proxy, 
              "https" : https_proxy
            }
URL = 'some_url'
cookie = 'some_cookie'    
headers = {'Cookie': cookie}    
payload = 'some_payload'

s = requests.Session()
response= s.post(URL, params=payload, proxies=proxyDict, headers=headers, verify=False)
print(response.text)

到目前为止,在PyCurl中,我得到了:

import pycurl
import sys

global str
str = ""
def wr(x):
    sys.stdout.write(x)


http_proxy  = 'some_proxy1'
https_proxy = 'some_proxy2'
proxyDict = { 
              "http"  : http_proxy, 
              "https" : https_proxy
            }
URL = 'some_url'
cookie = 'some_cookie'    
headers = {'Cookie': cookie}    
payload = 'some_payload'


c = pycurl.Curl()
c.setopt(c.URL, URL)
c.setopt(c.WRITEFUNCTION, wr)
c.setopt(c.PROXY, proxyDict)# ???
c.setopt(c.CONNECTTIMEOUT, 10)
c.setopt(c.HTTPHEADER, ['Cookie:cookie'])# ???
c.setopt(c.TIMEOUT, 10)
c.perform()

但是我不确定cookie和代理部分,也不知道如何发送有效载荷。

我也想禁用SSL验证。

0 个答案:

没有答案