Here are the examples of the python api request.post taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
0
Source : client.py
with MIT License
from Carsmaniac
with MIT License
from Carsmaniac
def _enqueue(self, msg):
"""Push a new `msg` onto the queue, return `(success, msg)`"""
timestamp = msg['timestamp']
if timestamp is None:
timestamp = datetime.utcnow().replace(tzinfo=tzutc())
message_id = msg.get('messageId')
if message_id is None:
message_id = uuid4()
require('integrations', msg['integrations'], dict)
require('type', msg['type'], string_types)
require('timestamp', timestamp, datetime)
require('context', msg['context'], dict)
# add anonymousId to the message if not passed
msg['anonymousId'] = msg['anonymousId'] or self.anonymoys_id
# copy the userId to context.traits
if msg['userId'] != None:
if 'traits' in msg['context'].keys():
msg['context']['traits']['userId'] = msg['userId']
else :
msg['context']['traits'] = {'userId': msg['userId']}
msg['context']['traits']['anonymousId'] = msg['anonymousId']
# add common
timestamp = guess_timezone(timestamp)
msg['timestamp'] = timestamp.isoformat()
msg['messageId'] = stringify_id(message_id)
msg['context']['library'] = {
'name': 'rudder-analytics-python',
'version': VERSION
}
msg['userId'] = stringify_id(msg.get('userId', None))
msg['anonymousId'] = stringify_id(msg.get('anonymousId', None))
msg = clean(msg)
# if send is False, return msg as if it was successfully queued
if not self.send:
return True, msg
if self.sync_mode:
post(self.write_key, self.host, timeout=self.timeout, batch=[msg])
return True, msg
try:
self.queue.put(msg, block=False)
return True, msg
except queue.Full:
print("Analytics queue is full, skipping")
return False, msg
def flush(self):
0
Source : consumer.py
with MIT License
from Carsmaniac
with MIT License
from Carsmaniac
def request(self, batch):
"""Attempt to upload the batch and retry before raising an error """
def fatal_exception(exc):
if isinstance(exc, APIError):
# retry on server errors and client errors
# with 429 status code (rate limited),
# don't retry on other client errors
return (400 < = exc.status < 500) and exc.status != 429
else:
# retry on all other errors (eg. network)
return False
@backoff.on_exception(
backoff.expo,
Exception,
max_tries=self.retries + 1,
giveup=fatal_exception)
def send_request():
post(self.write_key, self.host, timeout=self.timeout, batch=batch)
send_request()