Tech C**P
14 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
Hanlde basic authentication (username, password in header) via requests in python:
>>> from requests.auth import HTTPBasicAuth
>>> requests.get('https://api.github.com/user', auth=HTTPBasicAuth('user', 'pass'))
<Response [200]>

As you can see above you just need to provide username & password in auth parameter in order to have basic authentication.

#python #requests #authentication #basic #basic_authentication
How to add authentication to MongoDB?

At first you need to create an admin user, so bring up a mongo shell by typing mongo in your terminal and hit enter. The database that users are stored is admin, so switch to admin database:

use admin


Now by using createUser database method we will create a user called myUserAdmin:

db.createUser(
{
user: "myUserAdmin",
pwd: "1234qwer",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)

Disconnect the mongo shell.

The important note about mongo is to run it by --auth argument, otherwise authentication would not work:

mongod --auth --port 27017 --dbpath /data/db1

#mongodb #mongo #auth #authentication #create_user