无效的URI方案Python,MongoDB错误

时间:2016-12-26 09:44:24

标签: python mongodb pycharm

我试图在pycharm中创建一个使用MongoDB和Pymongo的项目。 但是我遇到了以下错误:

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

以下代码:

import pymongo

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

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

好的。我想到了 。只需要删除空间

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

输出:

<pymongo.cursor.Cursor object at 0x038B58D0>
该死的!我一直忘记Python是一种对空间敏感的编程语言