0

I'm trying to make a script to auto-login to this website and I'm having some troubles. I was hoping I could get assistance with making this work. I have the below code assembled but I get 'Your request cannot be processed at this time\n' in the bottom of what's returned to me when I should be getting some different HTML if it was successful:

from pyquery import PyQuery
import requests

url = 'https://licensing.gov.nl.ca/miriad/sfjsp?interviewID=MRlogin'
values = {'d_1553779889165': '[email protected]',
          'd_1553779889166': 'thisIsMyPassw0rd$$$',
          'd_1618409713756': 'true',
          'd_1642075435596': 'Sign in'
          }
r = requests.post(url, data=values)
print (r.content)
5
  • first you could use DevTools in Chrome/Firefox to see what browser sends to server.
    – furas
    Commented Sep 13, 2022 at 16:54
  • page doesn't send as normal form data but as multi-form data and this may need to send it as files=.
    – furas
    Commented Sep 13, 2022 at 16:55
  • you can also display r.request.body.decode() to see what you send to server. And you can compare it with values in DevTools
    – furas
    Commented Sep 13, 2022 at 16:58
  • @furas So I've opened up DevTools and went to the monitoring tab and logged in. I see a bunch of css and js files (I imagine it's what loaded when I clicked the Sign in button). But I'm having trouble finding exactly what my browser is sending to the server. Where should I be monitoring?
    – vahnx
    Commented Sep 13, 2022 at 17:42
  • load page with form, open DevTools, clear all connections, write data in login form and press button and see what you have in DevTool (eventually filter HTML connections) - first on list should be connection with method POST and it should sends your data. If you click on its URL then it should show details: headers, cookies, response, request, etc. And request should show what it sends to server. Normal form send string like name=value&other_name=other_value but this request send strings with ---- and Content-Disposition: form-data; name= and this means multi-form data.
    – furas
    Commented Sep 13, 2022 at 18:13

1 Answer 1

0

I do this in .NET, but I think the logic can be written in Python as well. Firstly, I always use Fiddler to capture requests that a webpage sends then identify the request which you want to replicate and add all the cookies and headers that are sent with it in your code.

After sending the login request you will get some cookies that will identify that you've logged in and you use those cookies to proceed further in your site. For example, if you want to retrieve user's info after logging in first you need to trick the server thinking that you are logged in and that is where those log in cookies will help you

Also, I don't think the login would be so simple through a script because if you're trying to automate a government site, they may have some anti-bot security there lying there, some kind of fingerprint or captcha.

Hope this helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.