示例#1
0
 def json_to_xml(self):
     try:
         root = {"root": self.json_value}
         xml = xmltodict.unparse(root, pretty=True)
     except ArithmeticError as e:
         pyapilog().error(e)
     return xml
示例#2
0
 def get(self, value=None):
     try:
         req = requests.get(self.url, params=value)
     except Exception as err:
         print(err)
     if req.status_code == 200:
         pyapilog().info(u"发送get请求: %s   服务器返回:  %s" % (req.url, req.status_code))
     else:
         pyapilog().error(u"发送get请求: %s   服务器返回:  %s\n error info: %s " % (req.url, req.status_code, req.text))
     return req.text
示例#3
0
 def post(self, value=None):
     params = urllib.urlencode(value)
     try:
         req = requests.post(self.url + "?%s" % params)
     except Exception as err:
         print(err)
     if req.status_code == 200:
         pyapilog().info(u"发送post请求: %s  服务器返回:  %s" % (req.url, req.status_code))
     else:
         pyapilog().error(u"发送post请求: %s   服务器返回:  %s\n error info: %s " % (req.url, req.status_code, req.text))
     return req.text
示例#4
0
 def post_json(self, value):
     head = {'content-type': 'application/json'}
     try:
         req = requests.post(self.url, data=json.dumps(value), headers=head)
         print(req.url)
     except Exception as err:
         print(err)
     if req.status_code == 200:
         pyapilog().info(u"发送post请求: %s  服务器返回:  %s" % (req.url, req.status_code))
         return req.text
     else:
         pyapilog().error(u"发送post请求: %s   服务器返回:  %s\n error info: %s " % (req.url, req.status_code, req.text))
示例#5
0
 def json_exit(self):
     try:
         falag = self.json_value["success"]
     except KeyError as e:
         falag = pyapilog().error(e)
     return falag
示例#6
0
 def __init__(self, json_value):
     try:
         self.json_value = json.loads(json_value)
     except ValueError as e:
         pyapilog().error(e)