Ejemplo n.º 1
0
	def post(self,sourceNumber):
		#added to make change timeout settings on appengine
		from google.appengine.api import urlfetch
		urlfetch.set_default_fetch_deadline(45)
		logging.info(urlfetch.get_default_fetch_deadline())
		
		#lazy import
		import json
		
		#Get necessary variables
		user = self.user
		sourceNumber = sourceNumber.replace("%2B","+")
		noteName = self.request.get('noteName')
		
		#Make Call
		response = calltrunk.makeCall(SourceNumber = sourceNumber)
		conversationId = response['Detail']['ConversationId']
		

		#Add to database
		newConversation = conversation()
		newConversation.user = user
		newConversation.cId = conversationId
		newConversation.title = noteName

		newConversation.put()
		self.redirect('/feed')
Ejemplo n.º 2
0
 def inner(*argv, **kwargv):
   orig_deadline = urlfetch.get_default_fetch_deadline()
   urlfetch.set_default_fetch_deadline(deadline)
   try:
     return func(*argv, **kwargv)
   finally:
     urlfetch.set_default_fetch_deadline(orig_deadline)
Ejemplo n.º 3
0
 def _fetch_async(self, url, **kwargs): # pylint: disable=no-self-use
     context = ndb.get_context()
     try:
         response = yield context.urlfetch(url, **kwargs)
     except DeadlineExceededError as err:
         logging.warn("Error fetching url %r: %r [deadline: %s]",
                      url, err, urlfetch.get_default_fetch_deadline())
     else:
         raise ndb.Return(response)
def sendRequest(chat_id, method, data, files = None, url_api = key.DEFAULT_API_URL, debugInfo=''):
    urlfetch.set_default_fetch_deadline(20)
    try:
        default_timeout = urlfetch.get_default_fetch_deadline()
        logging.info('default_timeout: {}'.format(default_timeout))
        url_api_mathod = url_api + method
        resp = requests.post(url_api_mathod, data=data, files = files)
        logging.info('Response: {}'.format(resp.text))
        respJson = json.loads(resp.text)
        success = respJson['ok']
        if success:
            return True
        else:
            p = person.getPersonByChatId(chat_id)
            status_code = resp.status_code
            error_code = respJson['error_code']
            description = respJson['description']
            if error_code == 403:
                # Disabled user
                p.setEnabled(False, put=True)
                #logging.info('Disabled user: '******'❗ Input user disactivated: ' + p.getFirstNameLastNameUserName()
                logging.debug(debugMessage)
                tell_admin(debugMessage)
            elif error_code == 400 and description == "Bad Request: chat not found":
                p.setEnabled(False, put=True)
                # user never opened a chat with this bot
            else:
                debugMessage = '❗ Raising unknown err ({}).' \
                               '\nStatus code: {}\nerror code: {}\ndescription: {}.'.format(
                    debugInfo, status_code, error_code, description)
                logging.error(debugMessage)
                # logging.debug('recipeint_chat_id: {}'.format(recipient_chat_id))
                logging.debug('Telling to {} who is in state {}'.format(p.chat_id, p.state))
                tell_admin(debugMessage)
    except:
        report_exception()
Ejemplo n.º 5
0
from .version import VERSION

__author__ = 'EasyPost <*****@*****.**>'
__version__ = VERSION
version_info = tuple(int(v) for v in VERSION.split('.'))


# use urlfetch as request_lib on google app engine, otherwise use requests
request_lib = None
# use a max timeout equal to that of all customer-facing backend operations
_max_timeout = 90
try:
    from google.appengine.api import urlfetch
    request_lib = 'urlfetch'
    # use the GAE application-wide "deadline" (or its default) if it's less than our existing max timeout
    _max_timeout = min(urlfetch.get_default_fetch_deadline() or 60, _max_timeout)
except ImportError:
    try:
        import requests
        request_lib = 'requests'
        requests_session = requests.Session()
    except ImportError:
        raise ImportError('EasyPost requires an up to date requests library. '
                          'Update requests via "pip install -U requests" or '
                          'contact us at [email protected].')

    try:
        version = requests.__version__
        major, minor, patch = [int(i) for i in version.split('.')]
    except Exception:
        raise ImportError('EasyPost requires an up to date requests library. '
Ejemplo n.º 6
0
from .version import VERSION

__author__ = 'EasyPost <*****@*****.**>'
__version__ = VERSION
version_info = tuple(int(v) for v in VERSION.split('.'))


# use urlfetch as request_lib on google app engine, otherwise use requests
request_lib = None
# use a max timeout equal to that of all customer-facing backend operations
_max_timeout = 90
try:
    from google.appengine.api import urlfetch
    request_lib = 'urlfetch'
    # use the GAE application-wide "deadline" (or its default) if it's less than our existing max timeout
    _max_timeout = min(urlfetch.get_default_fetch_deadline() or 60, _max_timeout)
except ImportError:
    try:
        import requests
        request_lib = 'requests'
        requests_session = requests.Session()
    except ImportError:
        raise ImportError('EasyPost requires an up to date requests library. '
                          'Update requests via "pip install -U requests" or '
                          'contact us at [email protected].')

    try:
        version = requests.__version__
        major, minor, patch = [int(i) for i in version.split('.')]
    except Exception:
        raise ImportError('EasyPost requires an up to date requests library. '
def _request(ctx, data, extra_headers, deadline=None):
    if extra_headers is None:
      extra_headers = dict()
    if deadline is None:
      deadline = urlfetch.get_default_fetch_deadline()
    return ctx.urlfetch(TRACKING_URI, payload=urllib.urlencode(data), method="POST", headers=extra_headers, deadline=deadline)