Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't login #4

Open
spacemud opened this issue May 2, 2017 · 2 comments
Open

Can't login #4

spacemud opened this issue May 2, 2017 · 2 comments

Comments

@spacemud
Copy link

spacemud commented May 2, 2017

I get an error message when attempting to login:

2017/05/02 20:48:47 https://laracasts.com/sessions returned wrong status code: 500, expected 200

My details are correct.

@mohessaid
Copy link

The problem is in the GetToken function which scrap the csrf token from the login page, I am no expert in go but after checking the source code, I found that you are still using the baseUrl as your target, which is wrong because the login page is under baseUrl/login, then there is the token, I don't know why using the gjuery something package, and because I didn't understand what you are doing by "find(login-button[token]) line I rewrote the function using
body, err := ioutil.ReadAll(resp.Body)
then convert the bytes array to a string like
bodyString := string(body[:])
then using regex to get the token

tokenValue := regexp.MustCompile(`[0-9a-zA-Z]{40,50}`)
token := tokenValue.FindString(bodyString)

And that's it

@spacemud
Copy link
Author

That seems to fix the login issue, yes. Unfortunately I think Laracasts has updated the site since this was released, which breaks other parts of the script that also depend on scraping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants