polyphemus11 polyphemus11 - 13 days ago 5
Python Question

Python How to choose field for POST data when multiple fields have the same name

I am having problems writing a POST request using the requests python module.
There are 8 input fields with this html mark up:

<input class="form-control col-md-9" name="submission[value]" id="submission_value" type="text">


Each is in it's own unique div. Example:

<div id="problem_7">
<input class="form-control col-md-9" name="submission[value]" id="submission_value" type="text">
</div>
<div id="problem_8">
<input class="form-control col-md-9" name="submission[value]" id="submission_value" type="text">
</div>


As there are 8 input boxes with an attribute name of "submission[value]", how can I specifically POST data to the one in #problem_8 ONLY?

DevTools shows this (after decoded) as what is sent in the POST data:

utf8=✓&_method=create&authenticity_token=0S9z6WoYNSggXFo/6HP99CZ67V4qn4+QGy8+l36BV24BlAxkCXDAedGHItuXpCDxs7sPtkA1jGUIgNaJMSaxMQ==&submission[id]=8&submission[value]=2222&commit=Submit

Below is how my POST data payload is currently set up:

payload = {
"submission[value]": x,
"authenticity_token":authenticity_token
}

Answer

You need to send the submission[id] field as well. You can see in your POST data that the following keys/values are sent:

utf8=✓&_method=create&authenticity_token=0S9z6WoYNSggXFo/6HP99CZ67V4qn4+QGy8+l36BV24BlAxkCXDAedGHItuXpCDxs7sPtkA1jGUIgNaJMSaxMQ==&submission[id]=8&submission[value]=2222&commit=Submit

  • utf8 =
  • _method = create
  • authenticity_token = <some long token value not relevant>
  • submission[id] = 8
  • submission[value] = 2222
  • commit = Submit

You should aim to replicate this as closely as possible. Looking at the source it seems like submission[id] needs to be set to the integer value of the problem you want.

Comments