示例#1
0
 def login(self):
     conf = self.conf
     host = self.host
     uri = host + conf["login"]
     headers = self.headers
     headers[
         "Content-Type"] = "application/x-www-form-urlencoded; charset=UTF-8"
     username = self.username
     if self.username is None or self.username == '':
         username = self.getuserlist()[self.runtimes]
         self.username = username
     params = {"_": ljy_base.base().timeStamp()}
     loginId = self.getloginId()
     if self.__version == "C04":
         data = {
             "loginId": "%s" % (self.username),
             "staticmm": "123456",
             "applicationId": "",
             "rememberPwd": True
         }
     else:
         data = {
             "loginId": "%s" % (loginId),
             "applicationId": "",
             "rememberPwd": True
         }
     data = ljy_base.base()._urlencode(data)
     result = ljy_base.base().postHTTP(uri,
                                       params=params,
                                       data=data,
                                       headers=headers,
                                       cookies=self.cookies)
     result = ljy_base.base().ResultTextConvert(result)
     try:
         self.userId = result["userLoginInfo"]["userId"]
         # print(self.userId,">",username)
     except Exception:
         ex = Exception(
             "error;error;error;error;error;error;error;error;'%s':登录失败<%s>"
             % (username, result["serverResult"]["resultMessage"]))
         raise ex
     return result
示例#2
0
 def Upload_MultipartFormData(self, file_path):
     conf = self.conf
     host = self.host
     uri = host + conf["upload"]
     headers = self.headers
     headers.pop("Content-Type")
     data = {"branchCode": "E000001"}
     #提交files表单固定格式,open(...)部分不能用变量代替:file ={'row_name':(filename,open(file_path,"rb"),'image/jpeg'<-RecContentType)}
     file = {
         'file':
         (file_path.split("\\")[-1], open(file_path,
                                          "rb"), 'application/vnd.ms-excel')
     }
     # file ={'file':(conf["filename"],open(".\\zero.jpg","rb"),'image/jpeg')}
     result = ljy_base.base().postHTTP(uri,
                                       data=data,
                                       files=file,
                                       headers=headers)
     result = ljy_base.base().ResultTextConvert(result)
     # ljy_base.base().showResult(result)
     file["file"][1].close()
     return result
示例#3
0
	def CustomMethod(self,httpMethod,uri,params=None,data=None,headers_add=None,cookies=None):
		# import pdb
		# pdb.set_trace()
		# print(uri,params,data,headers_add,cookies)
		headers=self.headers
		cookies=self.cookies
		if params is not None:
			try:
				params=json.loads(params)
			except:
				pass
			params=ljy_base.base()._urlencode(params)
		else:
			params=None
		if data is not None:
			data=data
		else:
			data=""
		if headers_add is not None:
			try:
				headers.update(json.loads(headers_add))
			except:
				pass
		else:
			pass
		if cookies is not None:
			try:
				cookies.update(json.loads(cookies))
			except:
				pass
		else:
			pass
		if httpMethod=="get":
			result=ljy_base.base().getHTTP(uri,params=params,headers=headers,cookies=cookies)
		else:
			result=ljy_base.base().postHTTP(uri,params=params,data=data,headers=headers,cookies=cookies)
		result=ljy_base.base().ResultTextConvert(result)
		print(result)
示例#4
0
 def getloginId(self):
     loginId = {"username": self.username, "password": self.conf["passwd"]}
     loginId = ljy_base.base()._urlencode(loginId)
     return ljy_base.base().To_Base64(loginId)
示例#5
0
 def getcookies(self):
     uri = self.host + self.conf["index"]
     result = ljy_base.base().getHTTP(uri)
     self.cookies = {"JSESSIONID": "%s" % (result.cookies["JSESSIONID"])}