CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Private Attributes
url_query.url_query Class Reference

Public Member Functions

def __init__
 
def send
 

Private Attributes

 _body
 
 _url
 
 _url_data
 

Detailed Description

Definition at line 23 of file url_query.py.

Constructor & Destructor Documentation

def url_query.url_query.__init__ (   self,
  url = None,
  url_data = None,
  body = None 
)

Definition at line 25 of file url_query.py.

25 
26  def __init__(self, url=None, url_data=None, body=None):
27  self._url = url
28  self._url_data = url_data
29  self._body = body

Member Function Documentation

def url_query.url_query.send (   self)

Definition at line 30 of file url_query.py.

References url_query.url_query._body, url_query.url_query._url, and url_query.url_query._url_data.

30 
31  def send(self):
32  if self._body:
33  return requests.post(self._url, data=self._body, params=self._url_data, verify=False).text
34  else:
35  return requests.get(self._url, params=self._url_data, verify=False).text
36 
37 """class url_query():
38 
39  def __init__(self, url=None, url_data=None, body=None, response_stream=None, timeout=60):
40  if not(url):
41  return None
42  self._url = url
43  self._r = pycurl.Curl()
44 
45  # set options for the request - of note is the fact that we do not verify the peer or the host - because
46  # CERN certificates are self-signed, and we only need the encryption from HTTPS, not the certificate checks.
47 
48  self._r.setopt(self._r.CONNECTTIMEOUT, timeout)
49  user_agent = "User-Agent: ConditionWebServices/1.0 python/%d.%d.%d PycURL/%s" % (sys.version_info[ :3 ] + (pycurl.version_info()[1],))
50  self._r.setopt(self._r.USERAGENT, user_agent)
51  # we don't need to verify who signed the certificate or who the host is
52  self._r.setopt(self._r.SSL_VERIFYPEER, 0)
53  self._r.setopt(self._r.SSL_VERIFYHOST, 0)
54  self._response = StringIO()
55 
56  if body:
57  if type(body) == dict:
58  body = urlencode(body)
59  elif type(body) == list:
60  body = json.dumps(body)
61 
62  self._r.setopt(self._r.POSTFIELDS, body)
63 
64  if url_data:
65  if type(url_data) == dict:
66  url_data = urlencode(url_data)
67  else:
68  exit("URL data '%s' for request to URL '%s' was not valid - should be a dictionary." % (str(url_data), url))
69 
70  # set the URL with url parameters if they were given
71  self._r.setopt(self._r.URL, url + (("?%s" % url_data) if url_data else ""))
72 
73  if response_stream and type(response_stream) != StringIO:
74  response_stream = StringIO()
75  # copy reference to instance variable
76  self._response = response_stream
77  elif not(response_stream):
78  self._response = StringIO()
79 
80  self._r.setopt(self._r.WRITEFUNCTION, self._response.write)
81 
82  def send(self):
83  failed = True
84  max_retries = 5
85  attempt = 0
86  # retry while we're within the limit for the number of retries
87  while failed and attempt < max_retries:
88  try:
89  self._r.perform()
90  failed = False
91  self._r.close()
92  return self._response.getvalue()
93  except Exception as e:
94  failed = True
95  attempt += 1
96  # this catches exceptions that occur with the actual http request
97  # not exceptions sent back from server side
98  if type(e) == pycurl.error and e[0] in [7, 52]:
99  # wait two seconds to retry
100  print("Request failed - waiting 3 seconds to retry.")
101  sleep(3)
102  # do nothing for now
103  pass
104  else:
105  print("Unforesoon error occurred when sending data to server.")
106  traceback.print_exc()
107  if attempt == max_retries:
raise NoMoreRetriesException(max_retries)"""

Member Data Documentation

url_query.url_query._body
private

Definition at line 28 of file url_query.py.

Referenced by url_query.url_query.send().

url_query.url_query._url
private

Definition at line 26 of file url_query.py.

Referenced by url_query.url_query.send(), and conddblib.Connection.session().

url_query.url_query._url_data
private

Definition at line 27 of file url_query.py.

Referenced by url_query.url_query.send().