1

I want to get data received from URL request but I can't access it following is my code

def save_stripe_info(request):
    data = request.body
    email = data[0]
    payment_method_id = data[1]
    print('mail=>  ',email,'  i=>  ',payment_method_id, 'hello =>  ',data)
    # some code

it is printing the following output

mail=>   45   i=>   45 hello =>   b'------WebKitFormBoundary2ndFleWNwV9sa24C\r\nContent-Disposition: form-data; name="email"\r\n\r\ntesti@gmail.com\r\n------WebKitFormBoundary2ndFleWNwV9sa24C\r\nContent-Disposition: form-data; name="payment_method_id"\r\n\r\npm_1K5wvrBbWBJ638dRyJJeYjnL\r\n------WebKitFormBoundary2ndFleWNwV9sa24C--\r\n'

and if I try email = data[email] it gives an error that list indices must be an integer.

how can I get email and payment_method_id from request.

I also tried

body_unicode = request.body.decode('utf-8')
body = json.loads(body_unicode)
content = body['email']

but this is giving error json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Tamil Selvan
  • 1,600
  • 1
  • 9
  • 25
Ruma
  • 86
  • 1
  • 18
  • It looks to me csv with `;` delimiter. – SNR Dec 12 '21 at 18:47
  • It seems to me that your question is similar to this one: https://stackoverflow.com/questions/16573332/jsondecodeerror-expecting-value-line-1-column-1-char-0 – Richard Valenz Dec 12 '21 at 18:51
  • It is multipart data, indicated by repeatedly transmitted: `------WebKitFormBoundary...\r\n` sections. Related: https://stackoverflow.com/questions/33369306/parse-multipart-form-data-received-from-requests-post. If possible try to change the content-type client side, parsing JSON is easier. – Maurice Meyer Dec 12 '21 at 18:52

0 Answers0