22 def __init__(self, url=None, url_data=None, body=None, response_stream=None, timeout=60):
26 self.
_r = pycurl.Curl()
31 self._r.setopt(self._r.CONNECTTIMEOUT, timeout)
32 user_agent =
"User-Agent: ConditionWebServices/1.0 python/%d.%d.%d PycURL/%s" % (sys.version_info[ :3 ] + (pycurl.version_info()[1],))
33 self._r.setopt(self._r.USERAGENT, user_agent)
35 self._r.setopt(self._r.SSL_VERIFYPEER, 0)
36 self._r.setopt(self._r.SSL_VERIFYHOST, 0)
40 if isinstance(body, dict):
41 body = urlencode(body)
42 elif isinstance(body, list):
43 body = json.dumps(body)
45 self._r.setopt(self._r.POSTFIELDS, body)
48 if isinstance(url_data, dict):
49 url_data = urlencode(url_data)
51 exit(
"URL data '%s' for request to URL '%s' was not valid - should be a dictionary." % (
str(url_data), url))
54 self._r.setopt(self._r.URL, url + ((
"?%s" % url_data)
if url_data
else ""))
56 if response_stream
and not isinstance(response_stream, StringIO):
57 response_stream = StringIO()
60 elif not(response_stream):
63 self._r.setopt(self._r.WRITEFUNCTION, self._response.write)
def __init__(self, url=None, url_data=None, body=None, response_stream=None, timeout=60)