Skip to content

Commit

Permalink
Merge pull request #6 from lawrencefoley/5-update-login
Browse files Browse the repository at this point in the history
Add CSRF token to login request. Fixes #5.
  • Loading branch information
lawrencefoley authored Jan 25, 2021
2 parents cf42c0d + ebf0015 commit be51450
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,4 @@ com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
/venv/
6 changes: 4 additions & 2 deletions .idea/kcpl.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion kcpl/kcpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ def __init__(self, username, password):
def login(self):
self.session = requests.Session()
logging.info("Logging in with username: " + self.username)
loginPayload = {"username": str(self.username), "password": str(self.password)}
login_form = self.session.get(self.loginUrl)
login_form_soup = BeautifulSoup(login_form.text, 'html.parser')
csrf_token = login_form_soup.select(".login-form > input")[0]["value"]
csrf_token_name = login_form_soup.select(".login-form > input")[0]["name"]
loginPayload = {"Username": str(self.username), "Password": str(self.password), csrf_token_name: csrf_token}
r = self.session.post(url=self.loginUrl, data=loginPayload, allow_redirects=False)
logging.debug("Login response: " + str(r.status_code))
r = self.session.get(self.accountSummaryUrl)
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

setup(
name='kcpl',
version='0.0.1',
version='0.0.2',
description='A utility that reads electric utility meter data from KCPL.com',
long_description=long_description,
url='https://github.com/lawrencefoley/kcpl',
author='Lawrence Foley',
author_email='[email protected]', # Optional
author_email='[email protected]',

# Classifiers help users find your project by categorizing it.
#
Expand All @@ -39,14 +39,14 @@

# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.9',
],

# This field adds keywords for your project which will appear on the
# project page. What does your project relate to?
#
# Note that this is a string of words separated by whitespace, not a list.
keywords='kcpl api utilities kansas-city', # Optional
keywords='kcpl evergy api utilities kansas-city', # Optional

# You can just specify package directories manually here if your project is
# simple. Or you can use find_packages().
Expand Down

0 comments on commit be51450

Please sign in to comment.