I am trying to log into a forum using python requests. This is the forum I'm trying to log into: http://fans.heat.nba.com/community/
Here's my code:
import requests
import sys
URL = "http://fans.heat.nba.com/community/index.php?app=core&module=global§ion=login"
def main():
session = requests.Session()
# This is the form data that the page sends when logging in
login_data = {
'ips_username': 'username',
'ips_password': 'password',
'signin_options': 'submit',
'redirect':'index.php?'
}
r = session.post(URL, data=login_data)
# Try accessing a page that requires you to be logged in
q = session.get('http://fans.heat.nba.com/community/index.php?app=members&module=messaging§ion=view&do=showConversation&topicID=4314&st=20#msg26627')
print(session.cookies)
print(r.status_code)
print(q.status_code)
if __name__ == '__main__':
main()
The URL is the login page on the forums. With the 'q' variable, the session tries to access a certain webpage on the forums (private messenger) that can only be accessed if you're logged in. However, the status code for that request returns '403', which means that I was unable to log in successfully.
Why am I unable to log in? In the 'login_data', 'ips_username' and 'ips_password' are the HTML forms. However, I believe I have the actual log-in commands ('signin_options','redirect') wrong.
Can somebody guide me to the correct log-in commands please?