1

I'm trying to get a website's source data after logging in but am having trouble logging in to get to the source. The url is the webpage I see after logging in. I.e. if I login on chrome, I can use url to go to where I need to get the source data.

I keep getting multiple errors, primarily handshake errors:

"sslv3 alert handshake failure", "bad handshake", "urllib3.exceptions.MaxRetryError", and I think the primary error is

Traceback (most recent call last): File "C:\Users\bwayne\AppData\Local\Programs\Python\Python36-32\lib\site-packages\urllib3\contrib\pyopenssl.py", line 441, in wrap_socket cnx.do_handshake()

File "C:\Users\bwayne\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenSSL\SSL.py", line 1716, in do_handshake self._raise_ssl_error(self._ssl, result)

File "C:\Users\bwayne\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenSSL\SSL.py", line 1456, in _raise_ssl_error _raise_current_error()

File "C:\Users\bwayne\AppData\Local\Programs\Python\Python36-32\lib\site-packages\OpenSSL_util.py", line 54, in exception_from_error_queue raise exception_type(errors)

OpenSSL.SSL.Error: [('SSL routines', 'ssl3_read_bytes', 'sslv3 alert handshake failure')]

During handling of the above exception, another exception occurred:

import requests, sys
import ssl
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager


ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
ctx.options |= ssl.OP_NO_SSLv2
ctx.options |= ssl.OP_NO_SSLv3
ctx.options |= ssl.OP_NO_TLSv1
ctx.options |= ssl.OP_NO_TLSv1_1

class Ssl3HttpAdapter(HTTPAdapter):
    def init_poolmanager(self, connections, maxsize, block=False):
        self.poolmanager = PoolManager(num_pools=connections,
                                       maxsize=maxsize,
                                       block=block,
                                       ssl_version=ssl.PROTOCOL_TLSv1)
url = "www.thewebsite.com"

def do_requests(url):
    payload = {'Username': 'myName', 'Password': 'myPass'} 
    headers = {'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Mobile Safari/537.36'}
    with requests.Session() as s:
        s.mount(url,Ssl3HttpAdapter())
        p = s.post(url, headers=headers, data=payload, verify=False)

def main(url):
    do_requests(url)


main(url)

How can I login? I've double and triple checked that the HTML names are correct:

enter image description here

BruceWayne
  • 22,923
  • 15
  • 65
  • 110
  • Have you tried changing the `user-agent` in your session? Maybe this website doesn't allow `python requests` as user-agent. And where exactly are you using `from OpenSSL import SSL`? – bergerg Oct 06 '17 at 20:28
  • @nutmeg64 - How do I change the user-agent? Also, I'm not - that was accidentally left in from other attempts I did, I'll remove that part. – BruceWayne Oct 06 '17 at 20:32
  • Take a look at [this](https://stackoverflow.com/questions/20759981/python-trying-to-post-form-using-requests) for a good example on how to send form data with `requests`. When you click this *url* in Chrome, does it redirect you? If it is, to what url? Maybe you should do the `POST` to that url instead? – bergerg Oct 06 '17 at 20:35
  • @nutmeg64 - When I go to the `url` in my code, it goes to the site I want - logged in and everything. I added `headers = {'User-Agent': 'Chrome/61.0'}` and did `p = s.post(url, headers=headers, data=payload)`, but that doesn't seem to do anything...same errors come up. Also, I am able to use Python to open the tab in chrome successfully. If there's a way to use an open Chrome session to save the URL of the active tab, I'm open to that too I suppose. – BruceWayne Oct 06 '17 at 20:48
  • When you do it from your browser it is already logged in because you did it once already and your browser remembers it. Try to logout of that site and go to that url again. – bergerg Oct 06 '17 at 21:01
  • @nutmeg64 - Logged out and closed Chrome. Opened chrome, tried to go to URL (just pasting it in Address Bar) - brings me to the login screen, which it should. And then, I ran the python code (with your above suggestions) and still same errors. – BruceWayne Oct 06 '17 at 21:05
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/156132/discussion-between-brucewayne-and-nutmeg64). – BruceWayne Oct 06 '17 at 21:06
  • Per the chat - it's been decided it's a *server-side* issue, and not with my code. I'm not sure if I should close or delete, so let me know what to do! – BruceWayne Oct 06 '17 at 22:06

0 Answers0