Diagnosing a 403 error when submitting a form with rvest

I am trying to create a logged in html session using rvest. I have set my user agent formally and double checked my username and password, and the form seems to align with the source code on the site, but I still get a 403 Forbidden erorr when submitting.

I'm sure there might be some options that I am missing that may help with the error, or at least better diagnose the specific reasons for it.


Current code:

uastring <- "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Safari/605.1.15"

gc <- html_session("https://gc.com/login", user_agent(uastring))

gc_form <- html_form(gc)[[1]]

# contents of gc_form
#  <form> 'frm_login' (POST /do-login)
#  <input hidden> 'csrfmiddlewaretoken': o9VB4V3Ba1QeRLONVWXA6GdPsEwPhzjI
#  <input email> 'email': 
#  <input password> 'password': 
#  <input submit> '': Sign In

filled_form <- gc_form %>% 
    'email' = '<my email>', 
    'password' = '<my password>'

# contents of filled_form
#<form> 'frm_login' (POST /do-login)
#  <input hidden> 'csrfmiddlewaretoken': o9VB4V3Ba1QeRLONVWXA6GdPsEwPhzjI
#  <input email> 'email': <my email>
#  <input password> 'password': ********
#  <input submit> '': Sign In

logged_in <- gc %>% submit_form(filled_form, submit = NULL)


Submitting with 'NULL'
Warning message:
In request_POST(session, url = url, body = request$values, encode = request$encode,  :
  Forbidden (HTTP 403).

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.