import pandas as pd from sentence_transformers import SentenceTransformer sbert_model = SentenceTransformer('bert-base-nli-mean-tokens') df = pd.read_csv('nytEditorialSnippets_GroundTruth.txt', sep = '\t') df_10 = df[0:10] df_100 = df[0:100] # 1. Using Sentence Encoder in a function on every record def get_embedding(input_sentence): return sbert_model.encode([input_sentence])[0] %%timeit df_out_1 = df_100['text'].apply(get_embedding) 9.15 s ± 317 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) %%time df_out_1 = df_100['text'].apply(get_embedding) CPU times: user 18.3 s, sys: 112 ms, total: 18.5 s Wall time: 9.25 s %%time df_out_1 = df_10['text'].apply(get_embedding) CPU times: user 1.97 s, sys: 7.88 ms, total: 1.98 s Wall time: 997 ms df_out_1 0 [-0.7970602, 0.47616163, 0.2621567, 0.38846374... 1 [-0.32450542, -0.10945253, 0.6443658, 0.212320... 2 [-0.2602994, -0.0036350375, 1.2917686, 0.12602... 3 [0.5173101, -0.86385506, 1.5003084, 0.76273316... 4 [-0.19630705, 1.611963, 0.8502133, 0.059544455... ... 95 [-0.7843676, 0.70446295, -0.86373883, 0.096476... 96 [-0.047543377, -1.0461698, 0.9984542, 0.776394... 97 [-0.5863306, 0.38590172, -0.15509816, 0.275745... 98 [0.22616625, 0.33843663, 0.030288033, 0.191214... 99 [0.40268317, 1.1528935, 0.3597172, 0.16918863,... Name: text, Length: 100, dtype: object type(df_out_1) pandas.core.series.Series # 2. Using Sentence Encoder on entire array of sentences at once %%timeit df_out_2 = sbert_model.encode(df_100['text'].values) 9.25 s ± 275 ms per loop (mean ± std. dev. of 7 runs, 1 loop each) %%time df_out_2 = sbert_model.encode(df_100['text'].values) CPU times: user 17.8 s, sys: 1 s, total: 18.8 s Wall time: 9.41 s df_out_2 array([[-0.7970604 , 0.4761617 , 0.262157 , ..., -0.2437577 , 1.1380528 , 0.28697717], [-0.32450542, -0.10945235, 0.64436567, ..., 0.14436643, -0.24656864, -0.18447737], [-0.26029944, -0.00363465, 1.2917686 , ..., 1.1463983 , -1.0714562 , -0.09548129], ..., [-0.5863306 , 0.38590172, -0.15509816, ..., -0.2937488 , -0.3724223 , 0.1826524 ], [ 0.22616649, 0.33843663, 0.03028765, ..., 0.66338176, -0.6620043 , 0.09410357], [ 0.40268335, 1.152894 , 0.35971704, ..., -0.9203086 , 0.17893644, 0.71039814]], dtype=float32) type(df_out_2) numpy.ndarray df_out_2.shape (100, 768)
Monday, September 19, 2022
Performance testing of BERT based Sentence Transformers for sentence encoding
Download Code
Sunday, September 18, 2022
Sentiment Analysis Using RNN with BOW indexing of words
Download Data
Download Code
import numpy as np import pandas as pd from sklearn.metrics import classification_report df = pd.read_csv('input/sentences_and_phrases_150k/train.csv') test_df = pd.read_csv('input/sentences_and_phrases_150k/test.csv') from numpy import random ix = list(range(df.shape[0])) ix = random.permutation(ix) div = int(df.shape[0] * 0.7) train_df = df.iloc[ix[0:div]] validation_df = df.iloc[ix[div:]] import seaborn as sns sns.countplot(x ='Sentiment', data = train_df) train_df['Sentiment'].value_counts() 2 55723 3 22917 1 19105 4 6492 0 5005 The below function is used to preprocess the train and test data. 1.fillna(0) -fills NaN values (if any )with zero 2.Regular expression is used to match only the text data from the phrase 3. The text is the split to get the sentence. 4. every sentence is appended to Corpus for next use Note: Stemming or leematization or stop word removal is not applied here. Practioners can consider doing it for better result. import nltk, re def func(X): X=X.fillna(0) messages = X.copy() messages.reset_index(inplace=True) corpus=[] for i in range(len(messages)): review = re.sub('[^a-zA-Z]',' ',str(messages['Phrase'][i])) review = review.split() review = ' '.join(review) corpus.append(review) return corpus corpus_train = func(train_df) corpus_validation = func(validation_df) corpus_test = func(test_df) def get_wordlist(corpus1): words = [] for phrase in corpus1: for word in phrase.split(): words.append(word) words.sort() return set(words) word_set_train = get_wordlist(corpus_train) word_set_validation = get_wordlist(corpus_validation) word_set_test = get_wordlist(corpus_test) def get_dicts(word_set): word_to_index = {} for i, word in enumerate(word_set): word_to_index[word] = i index_to_word = {index:word for (word, index) in word_to_index.items()} return word_to_index, index_to_word word_to_index_train, index_to_word_train = get_dicts(word_set_train) word_to_index_validation, index_to_word_validation = get_dicts(word_set_validation) word_to_index_test, index_to_word_test = get_dicts(word_set_test) def token(corpus, word_to_index): tokenized_list = [] for phrase in corpus: tokenized_format = [] for word in phrase.split(): index = word_to_index[word] tokenized_format.append(index) tokenized_list.append(tokenized_format) return np.array(tokenized_list, dtype='object') from tensorflow import keras X_train = token(corpus_train, word_to_index_train) X_validation = token(corpus_validation, word_to_index_validation) X_test = token(corpus_test, word_to_index_test) In order to train the RNN on the tokenized data, all text input must have the same length. We will limit the maximum review length to maxlen=30 by truncating longer reviews and padding shorter reviews with a null value (0). Keras pad_sequences() function is used to accomplish this. maxlen = 30 X_train_padded = keras.preprocessing.sequence.pad_sequences(X_train, maxlen=maxlen, padding='post') X_validation_padded = keras.preprocessing.sequence.pad_sequences(X_validation, maxlen=maxlen, padding='post') X_test_padded = keras.preprocessing.sequence.pad_sequences(X_test, maxlen=maxlen, padding='post') y_train = train_df.iloc[:,-1].values y_validation = validation_df.iloc[:,-1].values from sklearn.preprocessing import OneHotEncoder encoder = OneHotEncoder(sparse=False) y_train_encoded = encoder.fit_transform(y_train.reshape(-1, 1)) #import the Keras layers from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Embedding,Dense, Dropout, LSTM, Dropout vocabulary_size = len(word_to_index_train) + 1 embedding_size=30 A simple RNN model is built with 1 embedding layer, 1 simple RNN layer, 1 dense layer as hidden layer and one dense layer as output layer. 1.A Sequential model is appropriate for a plain stack of layers where each layer has exactly one input tensor and one output tensor. 2.Keras Embedding Layer takes encoded text data as input. Embedding layer is used as the first hidden layer of a network. It takes 3 arguments.Embedding(input dimension, out_dimension=embedding_size, trainable=True).Embedding layer has weights that are learned. 3.Simple RNN () class is a complete RNN layer in Keras with input unit = 32 neurons. It is a Fully-connected RNN where the output is to be fed back to input. for more detials visit the website: https://keras.io/api/layers/recurrent_layers/simple_rnn/ 3.A dense layer which is deeply connected with its preceding layer. The dense layer’s neuron in a model receives output from every neuron of its preceding layer, where neurons of the dense layer perform matrix-vector multiplication. Row vector of the output from the preceding layers (RNN layer) is equal to the column vector of the dense layer. 4. Last dense layer is the Output layer with 5 nodes indicating the probabilities of sentiment calculated. import tensorflow as tf model = tf.keras.Sequential([ tf.keras.layers.Embedding(vocabulary_size, embedding_size, trainable=True), tf.keras.layers.SimpleRNN(32), tf.keras.layers.Dense(10, activation='relu'), tf.keras.layers.Dense(5, activation='sigmoid') ]) model.summary() Model: "sequential_2" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= embedding_2 (Embedding) (None, None, 30) 503430 simple_rnn_2 (SimpleRNN) (None, 32) 2016 dense_4 (Dense) (None, 10) 330 dense_5 (Dense) (None, 5) 55 ================================================================= Total params: 505,831 Trainable params: 505,831 Non-trainable params: 0 _________________________________________________________________ Hyper Parameter We first need to compile our model by specifying the loss function and optimizer we want to use while training, as well as any evaluation metrics we’d like to measure. Specify the appropriate parameters, including at least one metric ‘accuracy’. Optimizer used:Adam optimizer is used as it has the most beneficial nature of its adaptive learning rate. It can compute adaptive learning rates for different parameters. Loss Function: Since, the label is one-hot encoded, categorical_crossentropy is used as loss function. suppose, the label is not one hot enocded, one can use Sparse_categorical_crossentropy as loss function. model.compile(optimizer='adam',loss='categorical_crossentropy',metrics=['accuracy']) model.fit(X_train_padded, y_train_encoded, batch_size=256, epochs=5 ) Epoch 1/5 427/427 [==============================] - 9s 19ms/step - loss: 1.2401 - accuracy: 0.5143 Epoch 2/5 427/427 [==============================] - 8s 18ms/step - loss: 1.0842 - accuracy: 0.5567 Epoch 3/5 427/427 [==============================] - 8s 18ms/step - loss: 1.0129 - accuracy: 0.5849 Epoch 4/5 427/427 [==============================] - 8s 18ms/step - loss: 0.9300 - accuracy: 0.6288 Epoch 5/5 427/427 [==============================] - 8s 18ms/step - loss: 0.8159 - accuracy: 0.6783 pred_validation = model.predict(X_validation_padded) pred1_validation = (pred_validation > 0.5).astype(int) labels = [0, 1, 2, 3, 4] LABELS_validation = [labels[i] for i in model.predict(X_validation_padded).argmax(axis=-1)] print(classification_report(validation_df['Sentiment'], y_pred = LABELS_validation, labels = labels)) precision recall f1-score support 0 0.06 0.03 0.04 2067 1 0.21 0.14 0.17 8168 2 0.56 0.64 0.60 23859 3 0.22 0.22 0.22 10010 4 0.08 0.11 0.09 2714 accuracy 0.40 46818 macro avg 0.23 0.23 0.22 46818 weighted avg 0.38 0.40 0.39 46818 pred = model.predict(X_test_padded) pred1=(pred > 0.5).astype(int) labels = ['negative', 'somewhat negative', 'neutral','somewhat positive','positive'] LABELS=[labels[i] for i in model.predict(X_test_padded).argmax(axis=-1)] predicted = pd.DataFrame({'Phrase': test_df.iloc[:,0].values, 'Sentiment': LABELS}) print(predicted)Tags: Technology,Natural Language Processing,
Thursday, September 15, 2022
You have divergent branches and need to specify out of three options (merge, rebase, fast-forward) how to reconcile them. What to do?
You have divergent branches and need to specify out of three options (merge, rebase, fast-forward) how to reconcile them. What to do?Tags: Technology,GitHub,Let's experiment and figure out what these three reconciling strategies do.
Clone a Server Copy
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/server/repo_for_testing$ git pull Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': Already up to date. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/server/repo_for_testing$ git log commit b20128a7b6148aa7ed668cfe2531a54418e61097 (HEAD -> main, origin/main, origin/HEAD) Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:21:37 2022 +0530 20220915Clone Three Local Copies
Local Copy 1
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1$ git clone https://github.com/ashishjain1547/repo_for_testing.git Cloning into 'repo_for_testing'... Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': remote: Enumerating objects: 39, done. remote: Counting objects: 100% (39/39), done. remote: Compressing objects: 100% (24/24), done. remote: Total 39 (delta 13), reused 23 (delta 4), pack-reused 0 Receiving objects: 100% (39/39), 8.45 KiB | 4.23 MiB/s, done. Resolving deltas: 100% (13/13), done.Local Copy 2
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2$ git clone https://github.com/ashishjain1547/repo_for_testing.git Cloning into 'repo_for_testing'... Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': remote: Enumerating objects: 39, done. remote: Counting objects: 100% (39/39), done. remote: Compressing objects: 100% (24/24), done. remote: Total 39 (delta 13), reused 23 (delta 4), pack-reused 0 Receiving objects: 100% (39/39), 8.45 KiB | 2.82 MiB/s, done. Resolving deltas: 100% (13/13), done.Local Copy 3
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3$ git clone https://github.com/ashishjain1547/repo_for_testing.git Cloning into 'repo_for_testing'... Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': remote: Enumerating objects: 39, done. remote: Counting objects: 100% (39/39), done. remote: Compressing objects: 100% (24/24), done. remote: Total 39 (delta 13), reused 23 (delta 4), pack-reused 0 Receiving objects: 100% (39/39), 8.45 KiB | 2.82 MiB/s, done. Resolving deltas: 100% (13/13), done. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3$Update the Server Copy
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/server/repo_for_testing$ echo " " > 20220915_2336.html (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/server/repo_for_testing$ git add -A (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/server/repo_for_testing$ git commit -m "20220915 II" [main 80b40f5] 20220915 II 1 file changed, 1 insertion(+) create mode 100644 20220915_2336.html (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/server/repo_for_testing$ git push Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Delta compression using up to 4 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 248 bytes | 248.00 KiB/s, done. Total 2 (delta 1), reused 0 (delta 0), pack-reused 0 remote: Resolving deltas: 100% (1/1), completed with 1 local object. To https://github.com/ashishjain1547/repo_for_testing.git b20128a..80b40f5 main -> mainRun Git Push Command on Local Copies Without Doing a Git Pull First.
Local Copy 1
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1$ cd repo_for_testing/ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ echo " " > 20220915_2340.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git add -A (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git commit -m "20220915 Update on local copy 1" [main a01092f] 20220915 Update on local copy 1 1 file changed, 1 insertion(+) create mode 100644 20220915_2340.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git push Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': To https://github.com/ashishjain1547/repo_for_testing.git ! [rejected] main -> main (fetch first) error: failed to push some refs to 'https://github.com/ashishjain1547/repo_for_testing.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git status On branch main Your branch is ahead of 'origin/main' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git pull Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Compressing objects: 100% (1/1), done. remote: Total 2 (delta 1), reused 2 (delta 1), pack-reused 0 Unpacking objects: 100% (2/2), 228 bytes | 228.00 KiB/s, done. From https://github.com/ashishjain1547/repo_for_testing b20128a..80b40f5 main -> origin/main hint: You have divergent branches and need to specify how to reconcile them. hint: You can do so by running one of the following commands sometime before hint: your next pull: hint: hint: git config pull.rebase false # merge (the default strategy) hint: git config pull.rebase true # rebase hint: git config pull.ff only # fast-forward only hint: hint: You can replace "git config" with "git config --global" to set a default hint: preference for all repositories. You can also pass --rebase, --no-rebase, hint: or --ff-only on the command line to override the configured default per hint: invocation. fatal: Need to specify how to reconcile divergent branches. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git status On branch main Your branch and 'origin/main' have diverged, and have 1 and 1 different commits each, respectively. (use "git pull" to merge the remote branch into yours) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git log commit a01092fe6048d236bb71b1ea95d80e6084a340aa (HEAD -> main) Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:41:11 2022 +0530 20220915 Update on local copy 1 commit b20128a7b6148aa7ed668cfe2531a54418e61097 Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:21:37 2022 +0530 20220915 (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git pull Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': hint: You have divergent branches and need to specify how to reconcile them. hint: You can do so by running one of the following commands sometime before hint: your next pull: hint: hint: git config pull.rebase false # merge (the default strategy) hint: git config pull.rebase true # rebase hint: git config pull.ff only # fast-forward only hint: hint: You can replace "git config" with "git config --global" to set a default hint: preference for all repositories. You can also pass --rebase, --no-rebase, hint: or --ff-only on the command line to override the configured default per hint: invocation. fatal: Need to specify how to reconcile divergent branches. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git config pull.rebase false (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git pull Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': Merge made by the 'ort' strategy. 20220915_2336.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 20220915_2336.html (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ ls -l total 64 -rw-rw-r-- 1 ashish ashish 29 Sep 15 23:31 20210528_test_branch.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:31 202107141543.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:31 202107141608.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:31 202107211228.txt -rw-rw-r-- 1 ashish ashish 12 Sep 15 23:31 202110111920.txt -rw-rw-r-- 1 ashish ashish 2 Sep 15 23:47 20220915_2336.html -rw-rw-r-- 1 ashish ashish 2 Sep 15 23:40 20220915_2340.txt -rw-rw-r-- 1 ashish ashish 2 Sep 15 23:31 20220915.txt -rw-rw-r-- 1 ashish ashish 7 Sep 15 23:31 Archana.txt -rw-rw-r-- 1 ashish ashish 45 Sep 15 23:31 Ashish -rw-rw-r-- 1 ashish ashish 11357 Sep 15 23:31 LICENSE -rw-rw-r-- 1 ashish ashish 10 Sep 15 23:31 newFile.txt -rw-rw-r-- 1 ashish ashish 36 Sep 15 23:31 README.md -rw-rw-r-- 1 ashish ashish 22 Sep 15 23:31 test_file_20210528.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git log commit a24385b836c5e877571693b5e15a5a44512c1053 (HEAD -> main) Merge: a01092f 80b40f5 Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:47:47 2022 +0530 Merge branch 'main' of https://github.com/ashishjain1547/repo_for_testing commit a01092fe6048d236bb71b1ea95d80e6084a340aa Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:41:11 2022 +0530 20220915 Update on local copy 1 commit 80b40f50dcfebbcc39766c30ae5cb5b253f6d0ba (origin/main, origin/HEAD) Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:37:45 2022 +0530 20220915 IILocal copy is ahead of server by two commits.
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git status On branch main Your branch is ahead of 'origin/main' by 2 commits. (use "git push" to publish your local commits) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git push Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': Enumerating objects: 6, done. Counting objects: 100% (6/6), done. Delta compression using up to 4 threads Compressing objects: 100% (4/4), done. Writing objects: 100% (4/4), 529 bytes | 529.00 KiB/s, done. Total 4 (delta 2), reused 0 (delta 0), pack-reused 0 remote: Resolving deltas: 100% (2/2), completed with 1 local object. To https://github.com/ashishjain1547/repo_for_testing.git 80b40f5..a24385b main -> main (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git status On branch main Your branch is up to date with 'origin/main'. nothing to commit, working tree cleanLocal Copy 2
$ git config pull.rebase true # rebase
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2$ cd repo_for_testing/ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ ls -l total 56 -rw-rw-r-- 1 ashish ashish 29 Sep 15 23:33 20210528_test_branch.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:33 202107141543.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:33 202107141608.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:33 202107211228.txt -rw-rw-r-- 1 ashish ashish 12 Sep 15 23:33 202110111920.txt -rw-rw-r-- 1 ashish ashish 2 Sep 15 23:33 20220915.txt -rw-rw-r-- 1 ashish ashish 7 Sep 15 23:33 Archana.txt -rw-rw-r-- 1 ashish ashish 45 Sep 15 23:33 Ashish -rw-rw-r-- 1 ashish ashish 11357 Sep 15 23:33 LICENSE -rw-rw-r-- 1 ashish ashish 10 Sep 15 23:33 newFile.txt -rw-rw-r-- 1 ashish ashish 36 Sep 15 23:33 README.md -rw-rw-r-- 1 ashish ashish 22 Sep 15 23:33 test_file_20210528.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git status On branch main Your branch is up to date with 'origin/main'. nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ echo "local copy 2" > 20220915_local_copy_2.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git add -A (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git commit -m "local copy 2" [main 824f879] local copy 2 1 file changed, 1 insertion(+) create mode 100644 20220915_local_copy_2.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git push Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': To https://github.com/ashishjain1547/repo_for_testing.git ! [rejected] main -> main (fetch first) error: failed to push some refs to 'https://github.com/ashishjain1547/repo_for_testing.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git status On branch main Your branch is ahead of 'origin/main' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git pull Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': remote: Enumerating objects: 7, done. remote: Counting objects: 100% (7/7), done. remote: Compressing objects: 100% (4/4), done. remote: Total 6 (delta 4), reused 4 (delta 2), pack-reused 0 Unpacking objects: 100% (6/6), 623 bytes | 311.00 KiB/s, done. From https://github.com/ashishjain1547/repo_for_testing b20128a..a24385b main -> origin/main hint: You have divergent branches and need to specify how to reconcile them. hint: You can do so by running one of the following commands sometime before hint: your next pull: hint: hint: git config pull.rebase false # merge (the default strategy) hint: git config pull.rebase true # rebase hint: git config pull.ff only # fast-forward only hint: hint: You can replace "git config" with "git config --global" to set a default hint: preference for all repositories. You can also pass --rebase, --no-rebase, hint: or --ff-only on the command line to override the configured default per hint: invocation. fatal: Need to specify how to reconcile divergent branches. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git status On branch main Your branch and 'origin/main' have diverged, and have 1 and 3 different commits each, respectively. (use "git pull" to merge the remote branch into yours) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git config pull.rebase true (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git pull Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': Successfully rebased and updated refs/heads/main. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ ls -l total 68 -rw-rw-r-- 1 ashish ashish 29 Sep 15 23:33 20210528_test_branch.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:33 202107141543.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:33 202107141608.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:33 202107211228.txt -rw-rw-r-- 1 ashish ashish 12 Sep 15 23:33 202110111920.txt -rw-rw-r-- 1 ashish ashish 2 Sep 16 00:00 20220915_2336.html -rw-rw-r-- 1 ashish ashish 2 Sep 16 00:00 20220915_2340.txt -rw-rw-r-- 1 ashish ashish 13 Sep 16 00:00 20220915_local_copy_2.txt -rw-rw-r-- 1 ashish ashish 2 Sep 15 23:33 20220915.txt -rw-rw-r-- 1 ashish ashish 7 Sep 15 23:33 Archana.txt -rw-rw-r-- 1 ashish ashish 45 Sep 15 23:33 Ashish -rw-rw-r-- 1 ashish ashish 11357 Sep 15 23:33 LICENSE -rw-rw-r-- 1 ashish ashish 10 Sep 15 23:33 newFile.txt -rw-rw-r-- 1 ashish ashish 36 Sep 15 23:33 README.md -rw-rw-r-- 1 ashish ashish 22 Sep 15 23:33 test_file_20210528.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git status On branch main Your branch is ahead of 'origin/main' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git log commit 858945ca963a48977eea5682e6dc54eb1f87eba1 (HEAD -> main) Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:58:20 2022 +0530 local copy 2 commit a24385b836c5e877571693b5e15a5a44512c1053 (origin/main, origin/HEAD) Merge: a01092f 80b40f5 Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:47:47 2022 +0530 Merge branch 'main' of https://github.com/ashishjain1547/repo_for_testing commit a01092fe6048d236bb71b1ea95d80e6084a340aa Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:41:11 2022 +0530 20220915 Update on local copy 1 commit 80b40f50dcfebbcc39766c30ae5cb5b253f6d0ba Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:37:45 2022 +0530 20220915 II commit b20128a7b6148aa7ed668cfe2531a54418e61097 Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:21:37 2022 +0530 20220915 (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git status On branch main Your branch is ahead of 'origin/main' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git push Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': Enumerating objects: 4, done. Counting objects: 100% (4/4), done. Delta compression using up to 4 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 305 bytes | 305.00 KiB/s, done. Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 remote: Resolving deltas: 100% (1/1), completed with 1 local object. To https://github.com/ashishjain1547/repo_for_testing.git a24385b..858945c main -> main (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git status On branch main Your branch is up to date with 'origin/main'. nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$Local Copy 3
$ git config pull.ff only # fast-forward only
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3$ cd repo_for_testing/ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git status On branch main Your branch is up to date with 'origin/main'. nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ ls -l total 56 -rw-rw-r-- 1 ashish ashish 29 Sep 15 23:34 20210528_test_branch.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:34 202107141543.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:34 202107141608.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:34 202107211228.txt -rw-rw-r-- 1 ashish ashish 12 Sep 15 23:34 202110111920.txt -rw-rw-r-- 1 ashish ashish 2 Sep 15 23:34 20220915.txt -rw-rw-r-- 1 ashish ashish 7 Sep 15 23:34 Archana.txt -rw-rw-r-- 1 ashish ashish 45 Sep 15 23:34 Ashish -rw-rw-r-- 1 ashish ashish 11357 Sep 15 23:34 LICENSE -rw-rw-r-- 1 ashish ashish 10 Sep 15 23:34 newFile.txt -rw-rw-r-- 1 ashish ashish 36 Sep 15 23:34 README.md -rw-rw-r-- 1 ashish ashish 22 Sep 15 23:34 test_file_20210528.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ echo "local copy 3" > 20220915_local_copy_3.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git add -A (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git commit -m "#" [main 5c8d1ff] # 1 file changed, 1 insertion(+) create mode 100644 20220915_local_copy_3.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git push Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': To https://github.com/ashishjain1547/repo_for_testing.git ! [rejected] main -> main (fetch first) error: failed to push some refs to 'https://github.com/ashishjain1547/repo_for_testing.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git status On branch main Your branch is ahead of 'origin/main' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git pull Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': remote: Enumerating objects: 10, done. remote: Counting objects: 100% (10/10), done. remote: Compressing objects: 100% (6/6), done. remote: Total 9 (delta 5), reused 6 (delta 2), pack-reused 0 Unpacking objects: 100% (9/9), 875 bytes | 437.00 KiB/s, done. From https://github.com/ashishjain1547/repo_for_testing b20128a..858945c main -> origin/main hint: You have divergent branches and need to specify how to reconcile them. hint: You can do so by running one of the following commands sometime before hint: your next pull: hint: hint: git config pull.rebase false # merge (the default strategy) hint: git config pull.rebase true # rebase hint: git config pull.ff only # fast-forward only hint: hint: You can replace "git config" with "git config --global" to set a default hint: preference for all repositories. You can also pass --rebase, --no-rebase, hint: or --ff-only on the command line to override the configured default per hint: invocation. fatal: Need to specify how to reconcile divergent branches. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git status On branch main Your branch and 'origin/main' have diverged, and have 1 and 4 different commits each, respectively. (use "git pull" to merge the remote branch into yours) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git config pull.ff only (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ ls -l total 60 -rw-rw-r-- 1 ashish ashish 29 Sep 15 23:34 20210528_test_branch.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:34 202107141543.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:34 202107141608.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:34 202107211228.txt -rw-rw-r-- 1 ashish ashish 12 Sep 15 23:34 202110111920.txt -rw-rw-r-- 1 ashish ashish 13 Sep 16 00:14 20220915_local_copy_3.txt -rw-rw-r-- 1 ashish ashish 2 Sep 15 23:34 20220915.txt -rw-rw-r-- 1 ashish ashish 7 Sep 15 23:34 Archana.txt -rw-rw-r-- 1 ashish ashish 45 Sep 15 23:34 Ashish -rw-rw-r-- 1 ashish ashish 11357 Sep 15 23:34 LICENSE -rw-rw-r-- 1 ashish ashish 10 Sep 15 23:34 newFile.txt -rw-rw-r-- 1 ashish ashish 36 Sep 15 23:34 README.md -rw-rw-r-- 1 ashish ashish 22 Sep 15 23:34 test_file_20210528.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git status On branch main Your branch and 'origin/main' have diverged, and have 1 and 4 different commits each, respectively. (use "git pull" to merge the remote branch into yours) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git log commit 5c8d1ff9d1e3d40daabf2b7cbcdc9f9b4e9003b3 (HEAD -> main) Author: Ashish Jain <ashishjain1547@gmail.com> Date: Fri Sep 16 00:14:43 2022 +0530 # commit b20128a7b6148aa7ed668cfe2531a54418e61097 Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:21:37 2022 +0530 20220915 commit 335cb1656a8b862733936531d0e00da92cea7f8f (origin/test_branch) Author: Ashish Jain <ashishjain1547@gmail.com> Date: Mon Oct 11 19:39:46 2021 +0530 Create Ashish commit 99da43ac015c1ed065796b4681ce2fdfd34d426c Author: unknown <ashishjain1547@gmail.com> Date: Mon Oct 11 19:37:33 2021 +0530 We will push this code with new file named Archana. commit be275fd83426869e3d8a27f8346ab903d6343faa Author: unknown <ashishjain1547@gmail.com> Date: Mon Oct 11 19:20:28 2021 +0530 20211011 1920 commit 9f1b42fe6b2cf1fbc3781cdb463b284f871ad291 Merge: d210505 087a5ca Author: unknown <ashishjain1547@gmail.com> Date: Wed Jul 21 12:41:37 2021 +0530 Merge branch 'test_branch' into main commit 087a5ca85b88f7303d025e8770183a6eabbeca7a Author: unknown <ashishjain1547@gmail.com> Date: Wed Jul 21 12:29:09 2021 +0530 20210721 1229 commit d2105058469fdb461a61578f8672e769d4426d79 Merge: daa4600 9017804 Author: Ashish Jain <ashishjain1547@gmail.com> Date: Wed Jul 14 16:25:29 2021 +0530 Merge pull request #1 from ashishjain1547/test_branch Test branch commit 901780465a07e7ce78932226db29a0898a07f4a2 Author: unknown <ashishjain1547@gmail.com> (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git pull Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': remote: Support for password authentication was removed on August 13, 2021. remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication. fatal: Authentication failed for 'https://github.com/ashishjain1547/repo_for_testing.git/' (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git pull Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': fatal: Not possible to fast-forward, aborting. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git status On branch main Your branch and 'origin/main' have diverged, and have 1 and 4 different commits each, respectively. (use "git pull" to merge the remote branch into yours) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git log commit 5c8d1ff9d1e3d40daabf2b7cbcdc9f9b4e9003b3 (HEAD -> main) Author: Ashish Jain <ashishjain1547@gmail.com> Date: Fri Sep 16 00:14:43 2022 +0530 # commit b20128a7b6148aa7ed668cfe2531a54418e61097 Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:21:37 2022 +0530 20220915 commit 335cb1656a8b862733936531d0e00da92cea7f8f (origin/test_branch) Author: Ashish Jain <ashishjain1547@gmail.com> Date: Mon Oct 11 19:39:46 2021 +0530 Create Ashish commit 99da43ac015c1ed065796b4681ce2fdfd34d426c Author: unknown <ashishjain1547@gmail.com> Date: Mon Oct 11 19:37:33 2021 +0530 We will push this code with new file named Archana. commit be275fd83426869e3d8a27f8346ab903d6343faa Author: unknown <ashishjain1547@gmail.com> Date: Mon Oct 11 19:20:28 2021 +0530 20211011 1920 commit 9f1b42fe6b2cf1fbc3781cdb463b284f871ad291 Merge: d210505 087a5ca Author: unknown <ashishjain1547@gmail.com> Date: Wed Jul 21 12:41:37 2021 +0530 Merge branch 'test_branch' into main commit 087a5ca85b88f7303d025e8770183a6eabbeca7a Author: unknown <ashishjain1547@gmail.com> Date: Wed Jul 21 12:29:09 2021 +0530 20210721 1229 commit d2105058469fdb461a61578f8672e769d4426d79 Merge: daa4600 9017804 Author: Ashish Jain <ashishjain1547@gmail.com> Date: Wed Jul 14 16:25:29 2021 +0530 Merge pull request #1 from ashishjain1547/test_branch Test branch commit 901780465a07e7ce78932226db29a0898a07f4a2 Author: unknown <ashishjain1547@gmail.com> (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$
Wednesday, September 14, 2022
Ten Commands For Day 1 With Ubuntu
1. (base) ashish@ashishdesktop:~$ ls anaconda3 Desktop Documents Downloads Pictures "PlayOnLinux's virtual drives" Public snap Videos 2. (base) ashish@ashishdesktop:~$ cd Desktop (base) ashish@ashishdesktop:~/Desktop$ ls 'The Tsunami (Class 8th).odt' ws (base) ashish@ashishdesktop:~/Desktop$ ls -l total 28 -rw-rw-r-- 1 ashish ashish 24290 Jul 6 21:37 'The Tsunami (Class 8th).odt' drwxrwxr-x 6 ashish ashish 4096 Mar 15 2022 ws (base) ashish@ashishdesktop:~/Desktop$ (base) ashish@ashishdesktop:~/Desktop$ 3. (base) ashish@ashishdesktop:~/Desktop$ mkdir moni (base) ashish@ashishdesktop:~/Desktop$ ls -l total 32 drwxrwxr-x 2 ashish ashish 4096 Sep 14 20:16 moni -rw-rw-r-- 1 ashish ashish 24290 Jul 6 21:37 'The Tsunami (Class 8th).odt' drwxrwxr-x 6 ashish ashish 4096 Mar 15 2022 ws (base) ashish@ashishdesktop:~/Desktop$ (base) ashish@ashishdesktop:~/Desktop$ cd moni (base) ashish@ashishdesktop:~/Desktop/moni$ (base) ashish@ashishdesktop:~/Desktop/moni$ (base) ashish@ashishdesktop:~/Desktop/moni$ ls -l total 0 4. (base) ashish@ashishdesktop:~/Desktop/moni$ touch moni.html (base) ashish@ashishdesktop:~/Desktop/moni$ ls -l total 0 -rw-rw-r-- 1 ashish ashish 0 Sep 14 20:21 moni.html (base) ashish@ashishdesktop:~/Desktop/moni$ 5. (base) ashish@ashishdesktop:~/Desktop/moni$ gedit moni.html (base) ashish@ashishdesktop:~/Desktop/moni$ (base) ashish@ashishdesktop:~/Desktop/moni$ ls -l total 4 -rw-rw-r-- 1 ashish ashish 35 Sep 14 20:27 moni.html (base) ashish@ashishdesktop:~/Desktop/moni$ 6. (base) ashish@ashishdesktop:~/Desktop/moni$ ls moni.html (base) ashish@ashishdesktop:~/Desktop/moni$ touch dummy.html (base) ashish@ashishdesktop:~/Desktop/moni$ (base) ashish@ashishdesktop:~/Desktop/moni$ ls -l total 4 -rw-rw-r-- 1 ashish ashish 0 Sep 14 21:58 dummy.html -rw-rw-r-- 1 ashish ashish 35 Sep 14 20:27 moni.html (base) ashish@ashishdesktop:~/Desktop/moni$ (base) ashish@ashishdesktop:~/Desktop/moni$ gedit dummy.html (base) ashish@ashishdesktop:~/Desktop/moni$ ls -l total 8 -rw-rw-r-- 1 ashish ashish 6 Sep 14 21:59 dummy.html -rw-rw-r-- 1 ashish ashish 35 Sep 14 20:27 moni.html (base) ashish@ashishdesktop:~/Desktop/moni$ (base) ashish@ashishdesktop:~/Desktop/moni$ rm dummy.html (base) ashish@ashishdesktop:~/Desktop/moni$ (base) ashish@ashishdesktop:~/Desktop/moni$ ls -l total 4 -rw-rw-r-- 1 ashish ashish 35 Sep 14 20:27 moni.html 7. (base) ashish@ashishdesktop:~/Desktop/moni$ cat moni.html <pre> my name is moni singh. </pre> 8. (base) ashish@ashishdesktop:~/Desktop/moni$ pwd /home/ashish/Desktop/moni 9. (base) ashish@ashishdesktop:~/Desktop/moni$ echo $USER ashish (base) ashish@ashishdesktop:~/Desktop/moni$ echo $HOME /home/ashish 10. (base) ashish@ashishdesktop:~/Desktop/moni$ uname -a Linux ashishdesktop 5.15.0-41-generic #44-Ubuntu SMP Wed Jun 22 14:20:53 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux (base) ashish@ashishdesktop:~/Desktop/moni$ uname LinuxTags: Technology,Linux,FAQs
Ques 1: What is Terminal? Ans 1: Terminal is a command line interface to the Ubuntu operating system. As of Oct, 2021: Terminal icon is depicted by a 'black background with letters ">_". "Terminal" is an application that is used to run command like: "ls", "cd" and "echo". manju@manju-desktop:~$ ls Desktop Documents Downloads Music Pictures Public Templates Videos manju@manju-desktop:~$ manju@manju-desktop:~$ ls -l total 32 drwxr-xr-x 2 manju manju 4096 Oct 1 23:34 Desktop drwxr-xr-x 2 manju manju 4096 Oct 1 20:56 Documents drwxr-xr-x 2 manju manju 4096 Apr 7 11:58 Downloads drwxr-xr-x 2 manju manju 4096 Apr 7 11:58 Music drwxr-xr-x 2 manju manju 4096 Apr 7 11:58 Pictures drwxr-xr-x 2 manju manju 4096 Apr 7 11:58 Public drwxr-xr-x 2 manju manju 4096 Apr 7 11:58 Templates drwxr-xr-x 2 manju manju 4096 Apr 7 11:58 Videos manju@manju-desktop:~$ cd Desktop manju@manju-desktop:~/Desktop$ ls -l total 4 -rw-rw-r-- 1 manju manju 537 Oct 1 23:34 'Beginner FAQs for Ubuntu.txt' --- Ques 2: How to browse internet? Answer 2: Use broswers: 1. Mozilla Firefox Browser. 2. Google Chrome. --- Ques 3: How to install Google Chrome. Answer: Use 'Ubuntu Software'. Step 1: Open "Ubuntu Software". Step 2: Press 'Ctrl+F' to launch 'Find and Search'. OR Step 1: Do a Google search in Firefox: "google chrome ubuntu" Step 2: On "Google Chrome Download" page, select "64 bit .deb (For Debian/Ubuntu)" radio button. Step 3: Click on "Accept and Install". ---
Tuesday, September 13, 2022
Sunday, September 11, 2022
Saturday, September 10, 2022
Monday, September 5, 2022
Hatzine 50 (Hydroxyzine)
Tags: Medicine for dogs,Information about Hydroxyzine
Hydroxyzine Uses
Hydroxyzine is used in the treatment of Anxiety and Skin conditions with inflammation & itching.How Hydroxyzine works
Hydroxyzine is an antihistaminic medication. In allergy, it works by blocking the action of a chemical messenger (histamine). This relieves allergy symptoms such as itching, swelling, and rashes. In short-term anxiety, it works by decreasing the activity in brain, thereby helping you feel relaxed/sleepy.Common side effects of Hydroxyzine
Sedation, Nausea, Vomiting, Upset stomach, Constipation
Creating a dummy database and collection in MongoDB Cloud and reading the dummy document using PyMongo
Login to MongoDB Atlas using your Google credentials. And perform the following actions as shown in screenshots below: 1: 2: 3: 4:Tags: Database,CloudNext, we check for "pymongo"
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$ python Python 3.9.12 (main, Apr 5 2022, 06:56:58) [GCC 7.5.0] :: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information. >>> import pymongo Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'pymongo' >>> exit() ENV.YML FILE: name: mongodb channels: - conda-forge dependencies: - pip - pymongoEnvironment Setup
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$ conda env create -f env.yml Collecting package metadata (repodata.json): done Solving environment: done ==> WARNING: A newer version of conda exists. <== current version: 4.12.0 latest version: 4.14.0 Please update conda by running $ conda update -n base -c defaults conda Downloading and Extracting Packages openssl-3.0.5 | 2.8 MB | ### | 100% python-3.10.6 | 29.0 MB | ### | 100% setuptools-65.3.0 | 782 KB | ### | 100% pymongo-4.2.0 | 1.3 MB | ### | 100% Preparing transaction: done Verifying transaction: done Executing transaction: done # # To activate this environment, use # # $ conda activate mongodb # # To deactivate an active environment, use # # $ conda deactivate - - - - - - - - - - (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$ conda activate mongodb (mongodb) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$ conda install ipykernel -c conda-forge Collecting package metadata (current_repodata.json): done Solving environment: done ==> WARNING: A newer version of conda exists. <== current version: 4.12.0 latest version: 4.14.0 Please update conda by running $ conda update -n base -c defaults conda ## Package Plan ## environment location: /home/ashish/anaconda3/envs/mongodb added / updated specs: - ipykernel The following packages will be downloaded: package | build ---------------------------|----------------- executing-1.0.0 | pyhd8ed1ab_0 19 KB conda-forge ipykernel-6.15.2 | pyh210e3f2_0 96 KB conda-forge ipython-8.4.0 | pyh41d4057_1 552 KB conda-forge jupyter_client-7.3.5 | pyhd8ed1ab_0 91 KB conda-forge psutil-5.9.2 | py310h5764c6d_0 350 KB conda-forge stack_data-0.5.0 | pyhd8ed1ab_0 24 KB conda-forge ------------------------------------------------------------ Total: 1.1 MB The following NEW packages will be INSTALLED: asttokens conda-forge/noarch::asttokens-2.0.8-pyhd8ed1ab_0 backcall conda-forge/noarch::backcall-0.2.0-pyh9f0ad1d_0 backports conda-forge/noarch::backports-1.0-py_2 backports.functoo~ conda-forge/noarch::backports.functools_lru_cache-1.6.4-pyhd8ed1ab_0 debugpy conda-forge/linux-64::debugpy-1.6.3-py310hd8f1fbe_0 decorator conda-forge/noarch::decorator-5.1.1-pyhd8ed1ab_0 entrypoints conda-forge/noarch::entrypoints-0.4-pyhd8ed1ab_0 executing conda-forge/noarch::executing-1.0.0-pyhd8ed1ab_0 ipykernel conda-forge/noarch::ipykernel-6.15.2-pyh210e3f2_0 ipython conda-forge/noarch::ipython-8.4.0-pyh41d4057_1 jedi conda-forge/noarch::jedi-0.18.1-pyhd8ed1ab_2 jupyter_client conda-forge/noarch::jupyter_client-7.3.5-pyhd8ed1ab_0 jupyter_core conda-forge/linux-64::jupyter_core-4.11.1-py310hff52083_0 libsodium conda-forge/linux-64::libsodium-1.0.18-h36c2ea0_1 matplotlib-inline conda-forge/noarch::matplotlib-inline-0.1.6-pyhd8ed1ab_0 nest-asyncio conda-forge/noarch::nest-asyncio-1.5.5-pyhd8ed1ab_0 packaging conda-forge/noarch::packaging-21.3-pyhd8ed1ab_0 parso conda-forge/noarch::parso-0.8.3-pyhd8ed1ab_0 pexpect conda-forge/noarch::pexpect-4.8.0-pyh9f0ad1d_2 pickleshare conda-forge/noarch::pickleshare-0.7.5-py_1003 prompt-toolkit conda-forge/noarch::prompt-toolkit-3.0.30-pyha770c72_0 psutil conda-forge/linux-64::psutil-5.9.2-py310h5764c6d_0 ptyprocess conda-forge/noarch::ptyprocess-0.7.0-pyhd3deb0d_0 pure_eval conda-forge/noarch::pure_eval-0.2.2-pyhd8ed1ab_0 pygments conda-forge/noarch::pygments-2.13.0-pyhd8ed1ab_0 pyparsing conda-forge/noarch::pyparsing-3.0.9-pyhd8ed1ab_0 python-dateutil conda-forge/noarch::python-dateutil-2.8.2-pyhd8ed1ab_0 pyzmq conda-forge/linux-64::pyzmq-23.2.1-py310h330234f_0 six conda-forge/noarch::six-1.16.0-pyh6c4a22f_0 stack_data conda-forge/noarch::stack_data-0.5.0-pyhd8ed1ab_0 tornado conda-forge/linux-64::tornado-6.2-py310h5764c6d_0 traitlets conda-forge/noarch::traitlets-5.3.0-pyhd8ed1ab_0 wcwidth conda-forge/noarch::wcwidth-0.2.5-pyh9f0ad1d_2 zeromq conda-forge/linux-64::zeromq-4.3.4-h9c3ff4c_1 Proceed ([y]/n)? y Downloading and Extracting Packages stack_data-0.5.0 | 24 KB | ### | 100% jupyter_client-7.3.5 | 91 KB | ### | 100% executing-1.0.0 | 19 KB | ### | 100% ipython-8.4.0 | 552 KB | ### | 100% ipykernel-6.15.2 | 96 KB | ### | 100% psutil-5.9.2 | 350 KB | ### | 100% Preparing transaction: done Verifying transaction: done Executing transaction: done - - - - - - - - - - (mongodb) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$ conda install jupyterlab -c conda-forge Collecting package metadata (current_repodata.json): done Solving environment: done ==> WARNING: A newer version of conda exists. <== current version: 4.12.0 latest version: 4.14.0 Please update conda by running $ conda update -n base -c defaults conda ## Package Plan ## environment location: /home/ashish/anaconda3/envs/mongodb added / updated specs: - jupyterlab The following packages will be downloaded: package | build ---------------------------|----------------- anyio-3.6.1 | pyhd8ed1ab_1 83 KB conda-forge babel-2.10.3 | pyhd8ed1ab_0 6.7 MB conda-forge cryptography-37.0.1 | py310h9ce1e76_0 1.5 MB json5-0.9.5 | pyh9f0ad1d_0 20 KB conda-forge jsonschema-4.15.0 | pyhd8ed1ab_0 64 KB conda-forge jupyter_server-1.18.1 | pyhd8ed1ab_0 232 KB conda-forge jupyterlab-3.4.5 | pyhd8ed1ab_0 5.8 MB conda-forge jupyterlab_server-2.15.1 | pyhd8ed1ab_0 49 KB conda-forge nbclassic-0.4.3 | pyhd8ed1ab_0 7.5 MB conda-forge notebook-shim-0.1.0 | pyhd8ed1ab_0 15 KB conda-forge pysocks-1.7.1 | pyha2e5f31_6 19 KB conda-forge requests-2.28.1 | pyhd8ed1ab_1 53 KB conda-forge sniffio-1.3.0 | pyhd8ed1ab_0 14 KB conda-forge websocket-client-1.4.1 | pyhd8ed1ab_0 42 KB conda-forge ------------------------------------------------------------ Total: 22.2 MB The following NEW packages will be INSTALLED: anyio conda-forge/noarch::anyio-3.6.1-pyhd8ed1ab_1 argon2-cffi conda-forge/noarch::argon2-cffi-21.3.0-pyhd8ed1ab_0 argon2-cffi-bindi~ conda-forge/linux-64::argon2-cffi-bindings-21.2.0-py310h5764c6d_2 attrs conda-forge/noarch::attrs-22.1.0-pyh71513ae_1 babel conda-forge/noarch::babel-2.10.3-pyhd8ed1ab_0 beautifulsoup4 conda-forge/noarch::beautifulsoup4-4.11.1-pyha770c72_0 bleach conda-forge/noarch::bleach-5.0.1-pyhd8ed1ab_0 brotlipy conda-forge/linux-64::brotlipy-0.7.0-py310h5764c6d_1004 certifi conda-forge/noarch::certifi-2022.6.15-pyhd8ed1ab_1 cffi conda-forge/linux-64::cffi-1.15.1-py310h255011f_0 charset-normalizer conda-forge/noarch::charset-normalizer-2.1.1-pyhd8ed1ab_0 cryptography pkgs/main/linux-64::cryptography-37.0.1-py310h9ce1e76_0 defusedxml conda-forge/noarch::defusedxml-0.7.1-pyhd8ed1ab_0 flit-core conda-forge/noarch::flit-core-3.7.1-pyhd8ed1ab_0 icu conda-forge/linux-64::icu-70.1-h27087fc_0 idna conda-forge/noarch::idna-3.3-pyhd8ed1ab_0 importlib-metadata conda-forge/linux-64::importlib-metadata-4.11.4-py310hff52083_0 importlib_metadata conda-forge/noarch::importlib_metadata-4.11.4-hd8ed1ab_0 importlib_resourc~ conda-forge/noarch::importlib_resources-5.9.0-pyhd8ed1ab_0 ipython_genutils conda-forge/noarch::ipython_genutils-0.2.0-py_1 jinja2 conda-forge/noarch::jinja2-3.1.2-pyhd8ed1ab_1 json5 conda-forge/noarch::json5-0.9.5-pyh9f0ad1d_0 jsonschema conda-forge/noarch::jsonschema-4.15.0-pyhd8ed1ab_0 jupyter_server conda-forge/noarch::jupyter_server-1.18.1-pyhd8ed1ab_0 jupyterlab conda-forge/noarch::jupyterlab-3.4.5-pyhd8ed1ab_0 jupyterlab_pygmen~ conda-forge/noarch::jupyterlab_pygments-0.2.2-pyhd8ed1ab_0 jupyterlab_server conda-forge/noarch::jupyterlab_server-2.15.1-pyhd8ed1ab_0 libiconv conda-forge/linux-64::libiconv-1.16-h516909a_0 libxml2 conda-forge/linux-64::libxml2-2.9.14-h22db469_4 libxslt conda-forge/linux-64::libxslt-1.1.35-h8affb1d_0 lxml conda-forge/linux-64::lxml-4.9.1-py310h5764c6d_0 markupsafe conda-forge/linux-64::markupsafe-2.1.1-py310h5764c6d_1 mistune conda-forge/noarch::mistune-2.0.4-pyhd8ed1ab_0 nbclassic conda-forge/noarch::nbclassic-0.4.3-pyhd8ed1ab_0 nbclient conda-forge/noarch::nbclient-0.6.7-pyhd8ed1ab_0 nbconvert conda-forge/noarch::nbconvert-7.0.0-pyhd8ed1ab_0 nbconvert-core conda-forge/noarch::nbconvert-core-7.0.0-pyhd8ed1ab_0 nbconvert-pandoc conda-forge/noarch::nbconvert-pandoc-7.0.0-pyhd8ed1ab_0 nbformat conda-forge/noarch::nbformat-5.4.0-pyhd8ed1ab_0 notebook conda-forge/noarch::notebook-6.4.12-pyha770c72_0 notebook-shim conda-forge/noarch::notebook-shim-0.1.0-pyhd8ed1ab_0 pandoc conda-forge/linux-64::pandoc-2.19.2-ha770c72_0 pandocfilters conda-forge/noarch::pandocfilters-1.5.0-pyhd8ed1ab_0 pkgutil-resolve-n~ conda-forge/noarch::pkgutil-resolve-name-1.3.10-pyhd8ed1ab_0 prometheus_client conda-forge/noarch::prometheus_client-0.14.1-pyhd8ed1ab_0 pycparser conda-forge/noarch::pycparser-2.21-pyhd8ed1ab_0 pyopenssl conda-forge/noarch::pyopenssl-22.0.0-pyhd8ed1ab_0 pyrsistent conda-forge/linux-64::pyrsistent-0.18.1-py310h5764c6d_1 pysocks conda-forge/noarch::pysocks-1.7.1-pyha2e5f31_6 python-fastjsonsc~ conda-forge/noarch::python-fastjsonschema-2.16.1-pyhd8ed1ab_0 pytz conda-forge/noarch::pytz-2022.2.1-pyhd8ed1ab_0 requests conda-forge/noarch::requests-2.28.1-pyhd8ed1ab_1 send2trash conda-forge/noarch::send2trash-1.8.0-pyhd8ed1ab_0 sniffio conda-forge/noarch::sniffio-1.3.0-pyhd8ed1ab_0 soupsieve conda-forge/noarch::soupsieve-2.3.2.post1-pyhd8ed1ab_0 terminado conda-forge/linux-64::terminado-0.15.0-py310hff52083_0 tinycss2 conda-forge/noarch::tinycss2-1.1.1-pyhd8ed1ab_0 typing_extensions conda-forge/noarch::typing_extensions-4.3.0-pyha770c72_0 urllib3 conda-forge/noarch::urllib3-1.26.11-pyhd8ed1ab_0 webencodings conda-forge/noarch::webencodings-0.5.1-py_1 websocket-client conda-forge/noarch::websocket-client-1.4.1-pyhd8ed1ab_0 zipp conda-forge/noarch::zipp-3.8.1-pyhd8ed1ab_0 Proceed ([y]/n)? y Downloading and Extracting Packages websocket-client-1.4 | 42 KB | ### | 100% nbclassic-0.4.3 | 7.5 MB | ### | 100% anyio-3.6.1 | 83 KB | ### | 100% sniffio-1.3.0 | 14 KB | ### | 100% pysocks-1.7.1 | 19 KB | ### | 100% babel-2.10.3 | 6.7 MB | ### | 100% notebook-shim-0.1.0 | 15 KB | ### | 100% jupyterlab_server-2. | 49 KB | ### | 100% json5-0.9.5 | 20 KB | ### | 100% jupyterlab-3.4.5 | 5.8 MB | ### | 100% jsonschema-4.15.0 | 64 KB | ### | 100% jupyter_server-1.18. | 232 KB | ### | 100% requests-2.28.1 | 53 KB | ### | 100% cryptography-37.0.1 | 1.5 MB | ### | 100% Preparing transaction: done Verifying transaction: done Executing transaction: done (mongodb) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$Installing kernel for Jupyter Lab
(mongodb) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$ python -m ipykernel install --user --name mongodb Installed kernelspec mongodb in /home/ashish/.local/share/jupyter/kernels/mongodb (mongodb) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$Testing Python Environment
import pymongo client = pymongo.MongoClient("mongodb+srv://$USERNAME:$PASSWORD@abc.xyz.mongodb.net/?retryWrites=true&w=majority") db = client.test --------------------------------------------------------------------------- ConfigurationError Traceback (most recent call last) Input In [1], in <cell line: 2>() 1 import pymongo ----> 2 client = pymongo.MongoClient("mongodb+srv://$USERNAME:$PASSWORD@abc.xyz.mongodb.net/?retryWrites=true&w=majority") 3 db = client.test File ~/anaconda3/envs/mongodb/lib/python3.10/site-packages/pymongo/mongo_client.py:726, in MongoClient.__init__(self, host, port, document_class, tz_aware, connect, type_registry, **kwargs) 722 if timeout is not None: 723 timeout = common.validate_timeout_or_none_or_zero( 724 keyword_opts.cased_key("connecttimeoutms"), timeout 725 ) --> 726 res = uri_parser.parse_uri( 727 entity, 728 port, 729 validate=True, 730 warn=True, 731 normalize=False, 732 connect_timeout=timeout, 733 srv_service_name=srv_service_name, 734 srv_max_hosts=srv_max_hosts, 735 ) 736 seeds.update(res["nodelist"]) 737 username = res["username"] or username File ~/anaconda3/envs/mongodb/lib/python3.10/site-packages/pymongo/uri_parser.py:469, in parse_uri(uri, default_port, validate, warn, normalize, connect_timeout, srv_service_name, srv_max_hosts) 467 if not _HAVE_DNSPYTHON: 468 python_path = sys.executable or "python" --> 469 raise ConfigurationError( 470 'The "dnspython" module must be ' 471 "installed to use mongodb+srv:// URIs. " 472 "To fix this error install pymongo with the srv extra:\n " 473 '%s -m pip install "pymongo[srv]"' % (python_path) 474 ) 475 is_srv = True 476 scheme_free = uri[SRV_SCHEME_LEN:] ConfigurationError: The "dnspython" module must be installed to use mongodb+srv:// URIs. To fix this error install pymongo with the srv extra: /home/ashish/anaconda3/envs/mongodb/bin/python -m pip install "pymongo[srv]"Fix:
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$ conda activate mongodb (mongodb) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$ python -m pip install "pymongo[srv]" Requirement already satisfied: pymongo[srv] in /home/ashish/anaconda3/envs/mongodb/lib/python3.10/site-packages (4.2.0) Collecting dnspython<3.0.0,>=1.16.0 Downloading dnspython-2.2.1-py3-none-any.whl (269 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 269.1/269.1 kB 123.6 kB/s eta 0:00:00 Installing collected packages: dnspython Successfully installed dnspython-2.2.1 (mongodb) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$ISSUE WITH SPECIAL CHARACTERS IN PASSWORD
import pymongo client = pymongo.MongoClient("mongodb+srv://$USERNAME:$PASSWORD@abc.xyz.mongodb.net/?retryWrites=true&w=majority") db = client.test --------------------------------------------------------------------------- InvalidURI Traceback (most recent call last) Input In [1], in <cell line: 2>() 1 import pymongo ----> 2 client = pymongo.MongoClient("mongodb+srv://$USERNAME:$PASSWORD@abc.xyz.mongodb.net/?retryWrites=true&w=majority") 3 db = client.test File ~/anaconda3/envs/mongodb/lib/python3.10/site-packages/pymongo/mongo_client.py:726, in MongoClient.__init__(self, host, port, document_class, tz_aware, connect, type_registry, **kwargs) 722 if timeout is not None: 723 timeout = common.validate_timeout_or_none_or_zero( 724 keyword_opts.cased_key("connecttimeoutms"), timeout 725 ) --> 726 res = uri_parser.parse_uri( 727 entity, 728 port, 729 validate=True, 730 warn=True, 731 normalize=False, 732 connect_timeout=timeout, 733 srv_service_name=srv_service_name, 734 srv_max_hosts=srv_max_hosts, 735 ) 736 seeds.update(res["nodelist"]) 737 username = res["username"] or username File ~/anaconda3/envs/mongodb/lib/python3.10/site-packages/pymongo/uri_parser.py:516, in parse_uri(uri, default_port, validate, warn, normalize, connect_timeout, srv_service_name, srv_max_hosts) 514 if "@" in host_part: 515 userinfo, _, hosts = host_part.rpartition("@") --> 516 user, passwd = parse_userinfo(userinfo) 517 else: 518 hosts = host_part File ~/anaconda3/envs/mongodb/lib/python3.10/site-packages/pymongo/uri_parser.py:71, in parse_userinfo(userinfo) 60 """Validates the format of user information in a MongoDB URI. 61 Reserved characters that are gen-delimiters (":", "/", "?", "#", "[", 62 "]", "@") as per RFC 3986 must be escaped. (...) 68 - `userinfo`: A string of the form <username>:<password> 69 """ 70 if "@" in userinfo or userinfo.count(":") > 1 or _unquoted_percent(userinfo): ---> 71 raise InvalidURI( 72 "Username and password must be escaped according to " 73 "RFC 3986, use urllib.parse.quote_plus" 74 ) 76 user, _, passwd = userinfo.partition(":") 77 # No password is expected with GSSAPI authentication. InvalidURI: Username and password must be escaped according to RFC 3986, use urllib.parse.quote_plusAll Issues Resolved. See Successful Code Run Below:
import pymongo import urllib uri = "mongodb+srv://$USERNAME:" + urllib.parse.quote_plus("$PASSWORD") + "@abc.xyz.mongodb.net/?retryWrites=true&w=majority" client = pymongo.MongoClient(uri) print(client) MongoClient(host=['ac-af4wahu-shard-00-02.xyz.mongodb.net:27017', 'ac-af4wahu-shard-00-01.xyz.mongodb.net:27017', 'ac-af4wahu-shard-00-00.xyz.mongodb.net:27017'], document_class=dict, tz_aware=False, connect=True, retrywrites=True, w='majority', authsource='admin', replicaset='atlas-3xaqbc-shard-0', tls=True) db = client['db1'] collection = db['ccn1'] print(collection.count_documents({})) # Output: 1 print(collection.find({})) <pymongo.cursor.Cursor at 0x7fd632c38850> import pprint for doc in collection.find(): pprint.pprint(doc) {'_id': ObjectId('6315c3a74afb509774a88467'), 'address': 'Delhi', 'name': 'Ashish Jain'}
Subscribe to:
Posts (Atom)