I'm trying to login to my own web2py website using requests in python 3.9.2. I can't seem to do it. my code is below. may you please review and let me know what I'm overlooking? thank you in advance, Lucas
BS = BeautifulSoup(response.text, 'lxml')
for i, e in enumerate(BS.select('input[name]')):
print(i, e)
if (e['name'][0] == '_'):
data[e['name']] = e['value']
import random, string
from requests_toolbelt import MultipartEncoder
boundary = '----WebKitFormBoundary' + ''.join(random.sample(string.ascii_letters + string.digits, 16))
m = MultipartEncoder(fields=data, boundary=boundary)
print(data)
headers = {
'Accept': "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate',
'Connection': 'keep-alive',
'User-Agent': user_agent,
'Content-Type': m.content_type
}
print(m)
print(headers)
print(response.url, response.history)
print()
print(response.status_code, response.encoding, response.headers, "...\n", response.text)
cookie.save()