0

I have 2 strings which are stored in variables

headers = str('{"Authorization":"'+auth+'"}')
otp = str('{"otp":"'+otp+'"}')

Using ast library I convert them to dictionary.

data = ast.literal_eval(otp)
head = ast.literal_eval(headers)

Output : 

{'otp': '0910'}
{'Authorization': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIU'}

But when I pass them to:

response = requests.post(url, params=data, headers = head)

I get this message

{'status': 'failure', 'message': 'invalid json'}

I understand this is a problem of single and double quotes but I am bit confused how to change single quotes to double quotes.

I tried using json.dumps() but this returns string which is not acceptable.

Please help.

  • 2
    It seems that the error comes from the server not from requests, can you verify what format the server is accepting? – johnII Dec 29 '17 at 05:42

1 Answers1

0

Use json instead of params

response = requests.post(url, json=data, headers=head)
Ronie Martinez
  • 1,254
  • 1
  • 10
  • 14