如何将下面的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验证。