CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
url_query.url_query Class Reference

Public Member Functions

def __init__ (self, url=None, url_data=None, body=None)
 
def send (self)
 

Private Attributes

 _body
 
 _url
 
 _url_data
 

Detailed Description

Definition at line 23 of file url_query.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 25 of file url_query.py.

25  def __init__(self, url=None, url_data=None, body=None):
26  self._url = url
27  self._url_data = url_data
28  self._body = body
29 
def __init__(self, dataset, job_number, job_id, job_name, isDA, isMC, applyBOWS, applyEXTRACOND, extraconditions, runboundary, lumilist, intlumi, maxevents, gt, allFromGT, alignmentDB, alignmentTAG, apeDB, apeTAG, bowDB, bowTAG, vertextype, tracktype, refittertype, ttrhtype, applyruncontrol, ptcut, CMSSW_dir, the_dir)

Member Function Documentation

◆ send()

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

Member Data Documentation

◆ _body

url_query.url_query._body
private

Definition at line 28 of file url_query.py.

Referenced by url_query.url_query.send().

◆ _url

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_data

url_query.url_query._url_data
private

Definition at line 27 of file url_query.py.

Referenced by url_query.url_query.send().