0

I can't find what I am doing wrong... I am trying to send a post req with custom values but cant seem to make it work always getting invaild format specifier.

Here is the original request:

headers = header

data = {
  'source': 'src_1MnugIHWW88ELdDvkI8CNwa1',
  'final_cres': '{"threeDSServerTransID":"d3b5c781-7227-443e-b784-b192fd82374a","transStatus":"Y","acsTransID":"30ba8be0-bf11-45e5-8273-05790c53f82b","messageType":"CRes","messageVersion":"2.1.0"}',
  'key': 'pk_live_51Jr1vKHWW88ELdDvVtlnR6MiY6ITPIVG4HHjjcFrJHS9izkO8m2g2nNCtOMe7KLpsUPgilz8VLoZf2NhtXZtiFIx00i5Ne7al6'
}
response = requests.post('some URL', headers=headers, data=data)

And here is my attempt I guess I messed up the final_cres key but I dont know how i would format it otherwise:

data = {
  'source': src,
  'final_cres': f'{"threeDSServerTransID":server_transaction_id,"transStatus":"Y","acsTransID":three_d_session,"messageType":"CRes","messageVersion":"2.1.0"}',
   'key': 'pk_live_51Jr1vKHWW88ELdDvVtlnR6MiY6ITPIVG4HHjjcFrHD4PizkO8m2g2nNCtOMe7KLpsUPgilz8VLoZf2NhtXZtiFIx00i5Ne7al6',
 }

As you can see i added the f before the final_cres value and replaced the values with with variables

Max S
  • 5
  • 1
  • Does this answer your question? [How do I escape curly-brace ({}) characters in a string while using .format (or an f-string)?](https://stackoverflow.com/questions/5466451/how-do-i-escape-curly-brace-characters-in-a-string-while-using-format-or) – Michael Butscher Mar 21 '23 at 03:59

1 Answers1

0

You are right, the final_cres is causing the issue. You don't need to format it, simply write the it as below:

server_transaction_id = 'abcdefgh'
three_d_session = 'xyzabc'

{"threeDSServerTransID":server_transaction_id,"transStatus":"Y","acsTransID":three_d_session,"messageType":"CRes","messageVersion":"2.1.0"}

or if you need to convert into string, use the following:

str({"threeDSServerTransID":server_transaction_id,"transStatus":"Y","acsTransID":three_d_session,"messageType":"CRes","messageVersion":"2.1.0"})
AbhinavB
  • 33
  • 1