Python Forum

Full Version: Login through a protected directory
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I've an index.html page stored in a protected folder, how do I get to it?

The code below doesn't work.
TIA

import requests

url='https://mypage.com/private/index.html'

values={'username':'user','password':'pass'}
r=requests.post(url, data=values)
print(r.content)
try:
url = 'file:///private/index.html'
the part after file/// needs to be full path
Thank you, will try. However, it’s a web folder and it may use .haccess as a security gate.
Solved. Here's the code:

import requests
import urllib3

urllib3.disable_warnings()

URL = 'https://www.mypage.com/private/'
HTACCESS_USER = 'me'
HTACCESS_PASSW = 'mypass'

data = requests.get(URL, verify = False, auth = (HTACCESS_USER, HTACCESS_PASSW))
print(data.text)  # passed .htaccess, perfect! now on login page