Reputation: 63
I'm not sure if such a thing is possible, but I am trying to submit to a form such as https://lambdaschool.com/contact using a POST request.
I currently have the following code:
import requests
payload = {"name":"MyName","lastname":"MyLast","email":"[email protected]","message":"My message"}
r = requests.post('http://lambdaschool.com/contact',params=payload)
print(r.text)
But I get the following error:
<title>405 Method Not Allowed</title>
etc.
Is such a thing possible to submit using a POST request?
Upvotes: 1
Views: 1249
Reputation: 191844
If it were that simple, you'd see a lot of bots attacking every login form ever.
That URL obviously doesn't accept POST requests. That doesn't mean the submit button is POST-ing to that page (though clicking the button also gives that same error...)
You need to open the chrome / Firefox dev tools and watch the request to see what happens on form submit and replicate that data in Python.
Another option would be the mechanize
or Selenium webdriver libraries to simulate a browser and fill out the form
Upvotes: 2
Reputation: 177685
params
is for query parameters. You either want data
, for a form encoded body, or json
, for a JSON body.
Upvotes: 1