1

I do need to create a long parameter list for a web page post which is not a dictionary based cause of multiple same keys.

Chromium shows this string as form data in the original request

p_action=RUN&p_mode=1&p_exec_mode=&p_page_url=&p_redirect_url=&p_reference_path=&p_arg_names=_title&p_arg_values=ARRAYSTART&p_arg_values=kschulz&p_arg_values=ARRAYEND&p_arg_names=reqnum&p_arg_values=ARRAYSTART&p_arg_values=0&p_arg_values=ARRAYEND&p_arg_names=_orderby_ord_1&p_arg_values=ASC

.... much more entries follow.

I know this is a crazy form data but I can not change this. p_arg_names is used multiple times and sometimes followed by multiple p_arg_value entries. Array Start and Array Stop are even existing... So I need the right order too.

params=dict... can not work here.

How can I provide requests.push(URL,DATA) a longer pure string without losing the

Content-Type:application/x-www-form-urlencoded
Saket Khandelwal
  • 347
  • 1
  • 11
stackelk
  • 61
  • 5
  • where is your code? there is no method like `requests.push(URL,DATA)` – Tobey Aug 31 '18 at 08:50
  • 1
    Possible duplicate of [Python : Trying to POST form using requests](https://stackoverflow.com/questions/20759981/python-trying-to-post-form-using-requests) – Tobey Aug 31 '18 at 08:52

2 Answers2

3

The params dict can work here, give it a list of the values.., eg:

r = requests.get('http://example.com', {'something': [1, 2, 3, 4, 5]})

(use .get/.put/.post/.patch - or whatever it is you mean by .push above)

The server will receive a request such as:

"GET /?something=1&something=2&something=3&something=4&something=5 HTTP/1.1" 200 396 "-" "python-requests/2.18.4"
Jon Clements
  • 138,671
  • 33
  • 247
  • 280
1

Using the requests module

import requests

request.post('http://127.0.0.1/8000/', params= {'p_arg_names': ['a', 'b']})

Results in

Post http://127.0.0.1/8000/?p_arg_names=a&p_arg_names=b HTTP/1.

Tobey
  • 1,400
  • 1
  • 10
  • 25