Login to side

  Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
diophantus7 Offline
Junior Member
Posts: 9
Joined: Nov 2016
Reputation: 0
Post: #1
Hey,

maybe a little off-topic but I hope you can help me or point me in the right direction. The page I created a plugin for has changed the site completely and with this the login procedure.
The sign-in url is something like https://app.example.com/users/sign_in. I signed in with Firefox and used it's Inspect Element tool to get the POST data. The curl command I got looks like
Code:
curl 'https://app.example.com/api/v1/auth/sign_in' -H 'Content-Type: application/json' -d '{"email":"username","password":"pass"}'
Note that the url here defers from the regular login url. Also note that I stripped down the headers from the command.
The curl command returns success and what seems to be my whole account information.
Now I can do the same in python with urllib2 and get the same result as the curl command. (The url being the same as the url in the curl command.) How can I manage to get a login to the usual site, i.e. https://app.example.com/users/sign_in and then get the page I am redirected to as a result? I think I don't understand this whole thing behind json.
Code:
req = urllib2.Request("https://app.example.com/users/sign_in", json_data, headers)
>>> response = urllib2.urlopen(req)
>>> the_page = response.read()
doesn't seem to work..
Do you guys need more information?
Would be glad to get some input. Thanks!
find quote
Skipmode A1 Offline
Skilled Python Coder
Posts: 311
Joined: Mar 2013
Reputation: 25
Post: #2
I would guess you have to do a http-post to login.

Here is an example: https://github.com/skipmodea1/plugin.vid...gs_play.py
find quote
Roman_V_M Offline
Team-Kodi Member
Posts: 1,142
Joined: Jun 2011
Reputation: 56
Location: Kyiv, Ukraine
Post: #3
You need to show more Python code than that? Have you set proper "Content-Type" header? What is your "json_data" actual value?

BTW, I strongly recommend to use requests library instead of built-in Python facilities.

Raspberry PI 2 + LibreELEC 8 (Kodi 17)
Samsung Galaxy Tab A 10.1 + Kodi 17 for Android
find quote
diophantus7 Offline
Junior Member
Posts: 9
Joined: Nov 2016
Reputation: 0
Post: #4
(2017-04-21 06:25)Skipmode A1 Wrote:  I would guess you have to do a http-post to login.

Here is an example: https://github.com/skipmodea1/plugin.vid...gs_play.py
That was how my plugin was handling the login before the update, and while the result has code 200 now, the site I get is the sign-in site again.

(2017-04-21 08:34)Roman_V_M Wrote:  You need to show more Python code than that? Have you set proper "Content-Type" header? What is your "json_data" actual value?

BTW, I strongly recommend to use requests library instead of built-in Python facilities.
Oh yes sure. Here are the headers I used
Code:
{'Content-Type': 'application/json', 'Host': 'app.example.com', 'Referer': 'https://app.example.com/users/sign_in', 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0'}
and the json_data is just
Code:
{"email":"username","password":"pass"}
find quote
Skipmode A1 Offline
Skilled Python Coder
Posts: 311
Joined: Mar 2013
Reputation: 25
Post: #5
Try this:

http://stackoverflow.com/questions/20475...l#20475712
find quote
diophantus7 Offline
Junior Member
Posts: 9
Joined: Nov 2016
Reputation: 0
Post: #6
(2017-04-21 12:51)Skipmode A1 Wrote:  Try this:

http://stackoverflow.com/questions/20475...l#20475712

The history is empty
find quote