3

I want to login my university portal with request module.

import requests
r = requests.post("https://sabis.sakarya.edu.tr/tr/Login", data={"userName":"1111","Password":"xxx"})
print(r.status_code)

but r.status_code return 500. Where i make mistake?

Batuhan Özkan
  • 137
  • 1
  • 4
  • 13
  • Possible duplicate of [python requests http response 500 (site can be reached in browser)](https://stackoverflow.com/questions/40442568/python-requests-http-response-500-site-can-be-reached-in-browser) – Mateus Martins Feb 27 '19 at 12:44

3 Answers3

0

If r.status_code returns 500 status code than your snippet is allright. The problem is from server side. Because, 5XX issues are considered as server internal issues

Devang Padhiyar
  • 3,427
  • 2
  • 22
  • 42
0

you need a authentication token for this to work. maybe your university has a API documentation available where you can see how to get this token. and even how to correctly do a post request using their API. enter image description here

J. peters
  • 74
  • 4
  • 1
    I can take authentication token by making get request, then how can i use that token? – Batuhan Özkan Feb 27 '19 at 13:16
  • store it in a variable and then add the value of that variable to the body or the header of your post request like this: – J. peters Feb 27 '19 at 13:37
  • like this: `payload = "{\n\t\"userName\":\"1111\",\n\t\"Password\":\"xxx\",\n\t\"__RequestVerificationToken\":\"njKqvavQ6C1ETT8qcivqX23jIhKxv-lAz0JmauV1btWoNNQonNReGqNJLRepJk-8IwrRo6ZoSImv04CoAw4KS96ewok1\"\n}" headers = {'content-type': 'application/json'} response = requests.request("POST", url, data=payload, headers=headers)` – J. peters Feb 27 '19 at 13:38
  • or this: `payload = "{\n\t\"userName\":\"1111\",\n\t\"Password\":\"xxx\",\n\t\n}" headers = { '__requestverificationtoken': "njKqvavQ6C1ETT8qcivqX23jIhKxv-lAz0JmauV1btWoNNQonNReGqNJLRepJk-8IwrRo6ZoSImv04CoAw4KS96ewok1", 'content-type': "application/json" } response = requests.request("POST", url, data=payload, headers=headers)` – J. peters Feb 27 '19 at 13:38
0

Maybe your post is lack of some information, eg. there're are other fields in the post data, or you should set the header in the post method.

pzjzeason
  • 139
  • 2
  • 9