In order to use authentication within a requests get or post function you just supply the auth
argument. Like this:
response = requests.get(url, auth = ('username', 'password'))
Refer to the Requests Authentication Documentation for more detailed info.
Using Chrome's developer tools you can inspect the elements of your html page that contains the form that you would like to fill out and submit. For an explanation of how this is done go here. You can find the data that you need to populate your post request's data argument. If you are not worried about verifying the security certificate of the site you are accessing then you can also specify that in the get argument list.
If your html page has these elements to use for your web form posting:
<textarea id="text" class="wikitext" name="text" cols="80" rows="20">
This is where your edited text will go
</textarea>
<input type="submit" id="save" name="save" value="Submit changes">
Then the python code to post to this form is as follows:
import requests
from bs4 import BeautifulSoup
url = "http://www.someurl.com"
username = "your_username"
password = "your_password"
response = requests.get(url, auth=(username, password), verify=False)
# Getting the text of the page from the response data
page = BeautifulSoup(response.text)
# Finding the text contained in a specific element, for instance, the
# textarea element that contains the area where you would write a forum post
txt = page.find('textarea', id="text").string
# Finding the value of a specific attribute with name = "version" and
# extracting the contents of the value attribute
tag = page.find('input', attrs = {'name':'version'})
ver = tag['value']
# Changing the text to whatever you want
txt = "Your text here, this will be what is written to the textarea for the post"
# construct the POST request
form_data = {
'save' : 'Submit changes'
'text' : txt
}
post = requests.post(url,auth=(username, password),data=form_data,verify=False)