Alan Hardin
Alan Hardin

Reputation: 13

python triple quote string adding multiple variables

I am using python 2.7. I have a triple quote string that I want to add 4 variables into. That string will then be used in a post request that our REST API will handle. Below is the string, it is shortened bc it is over 500 line long:

curDate = str(datetime.datetime.now().year)+"/"+str(datetime.datetime.now().month)+"/"+str(datetime.datetime.now().day)\
          +" "+str(datetime.datetime.now().hour)+":"+str(datetime.datetime.now().minute)+":"\
          +str(datetime.datetime.now().second)

...

payload = '''
   ...
"CaptureTime": %(captureTime),
   ...
"dataTime1": %(dataTime1)
   ...
"dataTime2": %(dataTime2)
   ...
"dataTime3": %(dataTime3)
   ...
"dataTime4": %(dataTime4)
   ...
''' % dict(captureTime=curDate, dataTime1=curDate, dataTime2=curDate, dataTime3=curDate, dataTime4=curDate)

This is the error I receive:

Traceback (most recent call last):
  File "/xxx/xxxx/xxxxxx/Rest/Post.py", line 6130, in <module>
    ''' % {'captureTime':curDate, 'dataTime1':curDate, 'dataTime2':curDate, 'dataTime3':curDate, 'dataTime4':curDate}
ValueError: unsupported format character ',' (0x2c) at index 204

Thank you for any and all help!

Upvotes: 0

Views: 376

Answers (1)

Luis Masuelli
Luis Masuelli

Reputation: 12323

The proble is you use:

%(captureTime),

Instead of qualifying the type (I assume you are trying to qualify as string):

%(captureTime)s,

And so the comma is not recognized as type qualifier for %.

Upvotes: 2

Related Questions