OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Passing cookies while logging in

  • Thread starter Thread starter AntoG
  • Start date Start date
A

AntoG

Guest
I would like to integrate python Selenium and Requests modules to authenticate on a website.

I am using the following code:

Code:
import requests
from selenium import webdriver

driver = webdriver.Firefox()
url = "some_url" #a redirect to a login page occurs
driver.get(url) #the login page is displayed

#making a persistent connection to authenticate
params = {'os_username':'username', 'os_password':'password'}
s = requests.Session()
resp = s.post(url, params) #I get a 200 status_code

#passing the cookies to the driver
driver.add_cookie(s.cookies.get_dict())

The problem is that when I enter the browser the login authentication is still there when I try to access the url even though I passed the cookies generated from the requests session.

How can I modify the code above to get through the authentication web page?
<p>I would like to integrate python Selenium and Requests modules to authenticate on a website.<br></p>
<p>I am using the following code:</p>
<pre><code>import requests
from selenium import webdriver

driver = webdriver.Firefox()
url = "some_url" #a redirect to a login page occurs
driver.get(url) #the login page is displayed

#making a persistent connection to authenticate
params = {'os_username':'username', 'os_password':'password'}
s = requests.Session()
resp = s.post(url, params) #I get a 200 status_code

#passing the cookies to the driver
driver.add_cookie(s.cookies.get_dict())
</code></pre>
<p>The problem is that when I enter the browser the login authentication is still there when I try to access the <code>url</code> even though I passed the cookies generated from the requests session. <br></p>
<p>How can I modify the code above to get through the authentication web page?</p>
 

Latest posts

Top