简体   繁体   中英

Call Rest API with user using Python requests

I want to call an API using requests.get() method where I have to give username and password as authentication like below.

response = requests.get(url, auth=requests.auth.HTTPBasicAuth('username', 'password'))

but I don't want to give password in auth as it will work dynamically where password will be encrypted.

so is there any way to do this by only giving username and not password?

There are a handful of methods to authenticate with an API, the most popular would probably be Token Authentication with something like JWT. This will allow your users to authenticate with your API without sending username and password. If you are using django rest framework, the link I provided should help to get you started.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM