lundi 25 mai 2020

testing requests method post to fill forms, 405 Method Not Allowed

I am trying to fill out a form using requests library post method and I am trying to test it on the following url: http://httpbin.org/forms/post. Have read its documentation and a number of stackoverflow questions and wrote the following code. (My expected result is the page that shows up when I fill those fields out manually and click submit).

import requests

payload = {'custname': 'tmp', 'custtel':'000000000', 'custemail':'x@abc.com','size':'small', 'topping':'Bacon', 'delivery':'21:00', 'Submit':'Submit order'}

r = requests.post('http://httpbin.org/forms/post',data=payload)

if (not r.ok): 
    print("Client or Server error. Status code=",r.status_code)

print(r.text)

It results in "405 Method Not Allowed" error.

Is there a better way to test out using requests to fill out forms, radio buttons etc? I have tried some other websites and examples but still not able to get the above functionality to work. I have read that the 'requests' is better way as compared to 'urllib' or 'mechanize' etc. Can it be used on dynamic websites also? Should I start using javascript? I have never used that before.

Aucun commentaire:

Enregistrer un commentaire