Persist lookup passes u character before data after lookup

38 views
Skip to first unread message

David Friday

unread,
May 17, 2025, 2:55:21 PMMay 17
to Bots Open Source EDI Translator
Hi,

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.

{'ToDate': '2025-05-17T11:00:00', 'Token': u'F5B220AB-5C16-424E-8ECD-75E512641A6A', 'FromDate': '2025-05-15T04:00:01', 'AgentNum': 'DTSA0000913', 'Criteria': 'DATERANGE'}

Has anybody seen this before and how to remove the u?

Thanks for any help,

David

Eppye Bots

unread,
May 18, 2025, 10:43:23 AMMay 18
to bots...@googlegroups.com
the u means it is a unicode string.
kind regards, Henk-Jan Ebbers


--
You received this message because you are subscribed to the Google Groups "Bots Open Source EDI Translator" group.
To unsubscribe from this group and stop receiving emails from it, send an email to botsmail+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/botsmail/480f99de-0aa0-41f4-8ac5-16c696c9ee40n%40googlegroups.com.

David Friday

unread,
May 18, 2025, 11:50:45 AMMay 18
to Bots Open Source EDI Translator
ok, that is not the problem that is giving me the 500 error code.

Thanks Henk-Jan,






Reply all
Reply to author
Forward
Message has been deleted
0 new messages