Post Request containing username/password using python for jwt - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Networking (https://python-forum.io/forum-12.html) +--- Thread: Post Request containing username/password using python for jwt (/thread-38479.html) |
Post Request containing username/password using python for jwt - anna - Oct-18-2022 Hi All, I am trying to get token through requests with user and password, there one small javascript provided by Vendor (this was demo in postman). How can I send this script through API call to get token, or is there any other way in python. Javascript in postman in Tests tab Quote:var res = pm.response.json(); Python script: import json import requests URL = "https://xx.23.105.xx:446/nmsnbi-rest/tapi/data/context/auth-context/auth-token" headers = { "accept": "application/json", "Content-Type": "application/json" } params = { "user": "Admin", "password": "Admin@3" } resp = requests.post(URL, headers = headers ,data=json.dumps(params),verify=False) #tk = json.loads(resp.text)['token'] print(resp.text) if resp.status_code != 200: print('error: ' + str(resp.status_code)) else: tk = json.loads(resp.text)['token'] print('token: ' + str(tk)) print('Success') RE: Post Request containing username/password using python for jwt - anna - Oct-18-2022 Ooops... sorry for bothering you guys, got the solution, below code worked for me import requests url = "https://xx.23.105.xx:446/nmsnbi-rest/tapi/data/context/auth-context/auth-token" payload = {} headers ={ 'user': 'Admin', 'password': 'Admin@3'} response = requests.request("POST", url, headers=headers, data = payload,verify=False) print(response.text.encode('utf8')) |