newsapps / beeswithmachineguns

A utility for arming (creating) many bees (micro EC2 instances) to attack (load test) targets (web applications).
http://apps.chicagotribune.com/
MIT License
6.43k stars 631 forks source link

HTTP request with post-file json data throwing errors #222

Closed indiranell closed 5 years ago

indiranell commented 6 years ago

How to make bees attack command for the below scenario:

POST HTTP request with input data(sample.json)

bees attack -n 100 -c 100 -XPOST -u 'http://qainterview.pythonanywhere.com/' -H Accept:/ -P application/json -p sample.json

and sample.json has below input data

{ "number": 20 } Getting HTTP Error 500 from the server, Is this error related to input data format?

Traceback (most recent call last): File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner self.run() File "/usr/lib/python2.7/threading.py", line 763, in run self.target(*self.args, *self.__kwargs) File "build/bdist.linux-x86_64/egg/beeswithmachineguns/bees.py", line 764, in attack _sting(param) File "build/bdist.linux-x86_64/egg/beeswithmachineguns/bees.py", line 383, in _sting response = urlopen(request) File "/usr/local/lib/python2.7/dist-packages/future-0.16.0-py2.7.egg/future/backports/urllib/request.py", line 171, in urlopen return opener.open(url, data, timeout) File "/usr/local/lib/python2.7/dist-packages/future-0.16.0-py2.7.egg/future/backports/urllib/request.py", line 500, in open response = meth(req, response) File "/usr/local/lib/python2.7/dist-packages/future-0.16.0-py2.7.egg/future/backports/urllib/request.py", line 612, in http_response 'http', request, response, code, msg, hdrs) File "/usr/local/lib/python2.7/dist-packages/future-0.16.0-py2.7.egg/future/backports/urllib/request.py", line 538, in error return self._call_chain(args) File "/usr/local/lib/python2.7/dist-packages/future-0.16.0-py2.7.egg/future/backports/urllib/request.py", line 466, in _call_chain result = func(*args) File "/usr/local/lib/python2.7/dist-packages/future-0.16.0-py2.7.egg/future/backports/urllib/request.py", line 620, in http_error_default raise HTTPError(req.full_url, code, msg, hdrs, fp) HTTPError: HTTP Error 500: Internal Server Error

Can someone please help me in correcting the input data file or share a sample post request with sample input data.

Spencer-Doak commented 6 years ago

A few things:

  1. Typically, in HTTP, you send the header: "Accept: /", not "Accept:/"
  2. Regardless of the Accept header provided, your request will not work because the site referenced expects application/x-www-form-urlencoded input, not application/json, in which case your sample input should be something like number=20.

All of that said, this is not an issue with the code-base of this application. This is an issue related to improper usage.

indiranell commented 5 years ago

Thanks for the clarification. Closing this issue