예제 #1
0
    def clean(self):
        raw_data = self.data

        recaptcha_response = raw_data.get('g-recaptcha-response')
        recaptcha_request = requests.posts(
            'https://www.google.com/recaptcha/api/siteverify',
            data={
                'secret': '6LfMSi4aAAAAAIdnb3hBJJK0GHGJ8OpZCPgAIfi_',
                'response': recaptcha_response
            })

        recaptcha_result = recaptcha_request.json()

        if not recaptcha_result.get('success'):
            self.add_error('comentario',
                           'Houve um erro, entre em contato conosco')

        cleaned_data = self.cleaned_data
        nome = cleaned_data.get('nome_comentario')
        email = cleaned_data.get('email_comentario')
        comentario = cleaned_data.get('comentario')

        if len(nome) < 5:
            self.add_error('nome_comentario',
                           'Nome dever possuir mais de 5 caracteres')
예제 #2
0
	def post_request(self, link, dataObject):
		try:
			cookies = pickle.load(open(self.cookiepath, "rb"))
		except:
			print("Couldn't load cookies for the request")
		else:
			res = requests.posts(self.link, data=self.dataObject, cookies=cookies)
			return res.status_code
예제 #3
0
def check_model(model_url, model_name, service_url, location):
    #my_logger.debug('HealthCheckService \t check_model ' + model_url)

    try:
        res = requests.get(url=model_url)  #ping models
        print 'Model is running:', model_url
    except Exception as e:
        data = {"modelName": model_name, "deploy_loc": location}
        print 'Model is DOWN', model_url
        print 'Before split:', service_url
        service_url = "/".join(service_url.split("/")[:-1])
        print 'Service url for scheduling:', service_url + "/modelDown"
        requests.post(service_url + "/modelDown", data=json.dumps(data))
        if location != 'Gateway':
            print 'Location is GATEWAY'
            deployServiceURL = requests.get(
                lb_URL + "/get_service_ip/deployService").json()
            if 'IP' in deployServiceURL:

                deployServiceURL = deployServiceURL[
                    'IP'] + ':' + deployServiceURL['port']
                print 'Deploy service url:', deployServiceURL
                print requests.posts(deployServiceURL + '/deploy',
                                     data=json.dumps(data))

                print 'Deploy service invoked'
            else:
                'Deploy service not registered'

        print 'Data for model:', json.dumps(data)
        data = json.dumps(data)
        scheduleURL = requests.get(lb_URL +
                                   "/get_service_ip/scheduleService").json()
        if 'ip' in scheduleURL:

            scheduleURL = scheduleURL['ip'] + ':' + scheduleURL['port']
            print 'schedule service url:', scheduleURL
            print requests.post("http://" + scheduleURL + post_schedule,
                                data=data)

            print 'scheduleURL service invoked'
        else:
            'scheduleURL service not registered'
예제 #4
0
def apply_token(tokens, app_endpoint='http://admin.intrustd.com.app.local'):
    if isinstance(tokens, str):
        tokens = [ tokens ]

    if not isinstance(tokens, list) and \
       not all(isinstance(token, str) for token in tokens):
        raise TypeError("tokens should be a string or list of strings")

    r = requests.posts(urljoin(app_endpoint, 'me/tokens'), json={ 'tokens': tokens })
    if r.status_code == 200:
        return
    elif r.status_code == 406:
        raise PermissionError("Token not yet authorized")
    elif r.status_code == 404:
        raise KeyError("Token not found")
    else:
        raise RuntimeError("Unknown status code: {}".format(r.status_code))
예제 #5
0
 def send(self,
          url,
          method,
          params=None,
          data=None,
          json=None,
          headers=None):
     #讲求请方法转化为小写lower
     method = method.lower()
     if method == "post":
         return requests.posts(url=url, json=json, data=data)
     elif method == "patch":
         return requests.patch(url=url,
                               json=json,
                               data=data,
                               headers=headers)
     elif method == "get":
         return self.se.get(url=url, params=params)
예제 #6
0
import requests

url = 'http://localhost:5000/api'

r = requests.posts(url, json={
    'exp': 75,
})
print(r.json())