After the persist lookup in a communication file, the lookup gets passed to the data in a API
outResponse request shown below:
import os
import requests
from django.utils.translation import ugettext as _
from bots.botsconfig import *
import bots.botsglobal as botsglobal
import bots.botslib as botslib
import bots.transform as transform
import bots.communication as communication
import datetime
from datetime import datetime, timedelta
import json
import httplib
import logging
logging.basicConfig(level=logging.DEBUG)
def connect(channeldict):
print 'connect',channeldict['idchannel']
def main(channeldict,ta,*args,**kargs):
ta.synall()
partner = 'DTS'
bearer = 'Bearer'
access_token = transform.persist_lookup(partner, bearer)
now = datetime.now()
minus_5_hours = now - timedelta(hours=5)
fromtimeformat = minus_5_hours.strftime('%Y-%m-%dT%H:00:01') # Current date time - 5 hours +1 second
totimeformat = now.strftime('%Y-%m-%dT%H:00:00') # Current date time
paramsDict = {
'mode': 'https',
'uri': '/API/Api/GetOrders',
'header': {
'Content-Type': 'application/json',
'Content-Type': 'charset=utf-8',
'Content-Type': 'application/x-www-form-urlencoded'
},
}
print fromtimeformat
print totimeformat
url = paramsDict.get('mode') + "://" + channeldict['host'] + paramsDict.get('uri') # Adds param dictionary items to make up URL
outResponse =
requests.post(url, headers = paramsDict.get('header'), data = {"Token":access_token, "AgentNum":"DTSA0000913", "Criteria":"DATERANGE", "FromDate":fromtimeformat, "ToDate":totimeformat})
if (outResponse.status_code != requests.codes.ok):
raise Exception(_(u'Http send error, response code is %s and content is %s.')%(outResponse.status_code, outResponse.text))
response = (outResponse.content)
if not response['status'] or response['message']:
raise botslib.CommunicationError('Status: %(status)s, Message: %(message)s' %response)
ta_to = (outResponse.content)
remove_ta = True
tofilename = unicode(ta_to)
tofile = botslib.opendata('PickupOrders.txt', 'wb')
tofile.write(outResponse.content)
tofile.close()
def disconnect(channeldict):
print 'disconnect',channeldict['idchannel']
Here is what is sent in the data part of the url which is all correct except the u shown below, this is what I believe is causing the 500 error.