pyCURL分段错误

时间:2015-08-15 01:56:15

标签: python python-2.7 curl segmentation-fault pycurl

我正在尝试使用Python的pyCURL(curl port to python)向HTTPS网址发送POST请求。问题是我的脚本退出时出现分段错误,这只发生在特定的URL上。对于其他URL(HTTP或HTTPS),它可以正常工作。此外,如果我使用命令行curl或urllib2,则请求成功。

from StringIO import StringIO
import pycurl
from urllib import urlencode

c = pycurl.Curl()
c.setopt(c.URL, 'https://monitoring.ad-sy.ch/cgi-bin/lg.cgi')
c.setopt(c.SSL_VERIFYPEER, 0) 
c.setopt(c.SSL_VERIFYHOST, 0)

post_data = {'router': 'rt-adsy-becs-01','protocol':'IPv4','addr':'198.41.208.143','query':'trace'}

storage = StringIO()

# Form data must be provided already urlencoded.
postfields = urlencode(post_data)
c.setopt(c.WRITEFUNCTION, storage.write)
c.setopt(c.POSTFIELDS, postfields)


c.perform()
c.close()

content = storage.getvalue()
print content

当我删除SSL选项c.setopt(c.SSL_VERIFYPEER, 0)c.setopt(c.SSL_VERIFYHOST, 0)时,它不会引发分段错误错误,但会引发以下异常:

pycurl.error: (51, 'gnutls_handshake() warning: The server name sent was not recognized')

0 个答案:

没有答案