0

I am logging into website by using below code...

payload = {'user': 'apple', 'password': 'banana'}
loginurl = 'http://12.345.678.910:8000/login'
r = requests.post(loginurl, data=payload)
data = r.json()
print(data)

As a response of above code i am getting output as below

{u'message': u'Logged in'}

Now in that website i am trying to get some response by using below get request...

DataURL = "http://12.345.678.910:8000/api/datasources/proxy/1/query?db=AB_CDE&q=SELECT%20sum(%22count%22)%20FROM%20%22gatling%22%20WHERE%20%22status%22%20%3D%20%27ok%27%20AND%20%22simulation%22%20%3D~%20%2Fabdokd-live*%2F%20AND%20time%20%3E%201544491800000ms%20and%20time%20%3C%201544495400000ms%20GROUP%20BY%20%22script%22&epoch=ms"
Datar = requests.get(url = DataURL)
resposne = Datar.json()
print(resposne)

As a response of above code i am getting below...

{u'message': u'Unauthorized'}

Which is not expected as in the previous step i already logged into the website. Can someone help me to correct my code?

Mohamed Thasin ah
  • 10,754
  • 11
  • 52
  • 111
SG131712
  • 135
  • 3
  • 13
  • Does this site set a cookie? –  Feb 14 '19 at 09:45
  • Yes it uses Cookies. I can see, it uses 3 session cookies and those cookies are passed in request headers in the next request. Can you please help me to capture those cookie values from login page and send in request headers to get the response of the next get request. – SG131712 Feb 14 '19 at 10:47

1 Answers1

2

You will probably need to look into how the authentication mechanism works in HTTP. It's most likely that your server is returning either a cookie or some sort of other identification header. Cookies are easiest because the browser will (to a first approximation) automatically return the cookies it gets form a server when making further requests. Your existing code isn't doing that.

Since you are using the requests library you should look at the answer to this question, which might shed some light on the problem.

holdenweb
  • 33,305
  • 7
  • 57
  • 77