Using python requests module and BS4 to login on an Wordpress based website

dear OpenSuse-Experts.

finally i am happy that python seems to run well on my opensuse-42.3 box.

**what happened: **I’m trying to login to a Wordpress based website using python’s request module and beautifulsoup4.
It seems like the code fails to sucessfully login. Also, there is no csrf token on the website. How do I sucessfully login to the website?


import requests
import bs4 as bs
with requests.session() as c:
    link="https://gpldl.com/sign-in/" #link of the webpage to be logged in
    initial=c.get(link) #passing the get request
     login_data={"log":"*****","pwd":"******"} #the login data from any  account on the site. Stars must be replaced with username and password
    page_login=c.post(link, data=login_data) #posting the login data into the link
    print(page_login) #checking status of requested page
    page=c.get("https://gpldl.com/my-gpldl-account/") #requesting source code of logged in page
    good_data = bs.BeautifulSoup(page.content, "lxml") #parsing it with BS4
    print(good_data.title) #printing this gives the title that is got from the page when accessed from an logged-out account
 

i got back:

martin@linux-3645:~/dev/python> python w1.py
Traceback (most recent call last):
  File "w1.py", line 1, in <module>
    import requests
ImportError: No module named requests

well: Requests is not a built in module (does not come with the default python installation), so you will have to install it:
OSX/Linux

i used this command:

Use $ sudo pip install requests

if we have pip installed

Alternatively we can also use

 sudo easy_install -U requests 

if we have easy_install installed.


martin@linux-3645:~/dev/python> sudo pip install requests
Requirement already satisfied: requests in /usr/lib/python3.4/site-packages
martin@linux-3645:~/dev/python> 

btw - see this …:

martin@linux-3645:~/dev/python> sudo pip install requests 
Requirement already satisfied: requests in /usr/lib/python3.4/site-packages 
martin@linux-3645:~/dev/python>

so what can i do now? -

greetings dilbertone

Just noticed your post and no answers yet…

An Internet search of “ImportError: No module named requests” returns hits that describe many possible causes… including

Not installed
Insufficient version
Bad path (including the possibility you’have more than one Python installed)
Not loaded

You may have to methodically work your way through the many possibilities in the many search hits.
One good suggestion in the hits that likely automatically addresses many possibilities is to build your app in a virtualenv so that you can have tight control over your python environment.If you do this, I recommend the use of pyenv to enhance managing your virtualenv as described in the following recent Forum thread

https://forums.opensuse.org/showthread.php/529448-installing-python-3-6-on-leap

HTH,
TSU