Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid URI Scheme Python , MongoDB Error

I was trying to create a project in pycharm which uses MongoDB and Pymongo. But I encountered the following error :

Traceback (most recent call last):
File "C:/Users/IngeniousAmbivert/PycharmProjects/terminal_blog/app.py", line 6, in <module>
client = pymongo.MongoClient(uri)
File "C:\Users\IngeniousAmbivert\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pymongo\mongo_client.py", line 400, in __init__"%s" % (entity[:idx],))
pymongo.errors.InvalidURI: Invalid URI scheme:  mongodb

For the following code :

import pymongo

uri = " mongodb://127.0.0.1:27017"
client = pymongo.MongoClient(uri)
database = client['stack']
collection = database['students']
students = collection.find({})
print(students)

Any help will be appreciated .

like image 865
Ingenious_Ambivert Avatar asked Apr 15 '26 02:04

Ingenious_Ambivert


1 Answers

Okay . I figured it out . Just needed to remove the space

uri = " mongodb://127.0.0.1:27017/" = Error
uri = "mongodb://127.0.0.1:27017" = No Error

Output :

<pymongo.cursor.Cursor object at 0x038B58D0>

Damn ! I keep forgetting Python is a space sensitive programming language

like image 63
Ingenious_Ambivert Avatar answered Apr 17 '26 14:04

Ingenious_Ambivert