pycharm 无效的URI方案Python,MongoDB错误

8ljdwjyq  于 2022-11-08  发布在  PyCharm
关注(0)|答案(2)|浏览(153)

我试图在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)

任何帮助都将不胜感激。

bksxznpy

bksxznpy1#

好吧。我想出来了。只是需要去掉

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

输出量:

<pymongo.cursor.Cursor object at 0x038B58D0>

该死!我总是忘记Python是一种对空格敏感的编程语言

oxf4rvwz

oxf4rvwz2#

[我得到了URI无效错误。对于我搜索这个网站,这里有一个解决方案。它已经在我的脚本中实现(client = pymongo.MongoClient(uri)),但仍然显示错误。]

相关问题