[Invalid] Python-调用mongodb功能无法使用
Opened this issue · 2 comments
Ghomeling commented
Search before asking
- I searched in the issue and found nothing similar. | 我查找了并确认issue列表无相似报告。
Sonic version
version2.6.4
Deploy platform
agent:windows10系统
server:ubuntu系统
Minimal reproduce step
- 自定义python代码如下:
import pymongo
class Mongodb:
def connect_mongodb(self):
client = pymongo.MongoClient('mongodb://root:xxxx!@xxxxx:27017/?authSource=admin')
db = client.pcGlobalBase
rs = db.gmMessageEmail.find().sort({"createTime":-1}).limit(1)
for result in rs:
title = result.get("title")
code = title.split(" ")[0]
print(code)
if name == 'main':
mongoUtil = Mongodb()
result = mongoUtil.connect_mongodb()
- python直接本地执行是ok的,但是用sonic的自定义代码执行就会失败:
Traceback (most recent call last):
File "D:\software\sonic-agent-v2.6.2-windows_x86_64\test-output\db2f1a7e-9452-40a8-a41b-36a0175bd9d8.py", line 16, in
result = mongoUtil.connect_mongodb()
File "D:\software\sonic-agent-v2.6.2-windows_x86_64\test-output\db2f1a7e-9452-40a8-a41b-36a0175bd9d8.py", line 8, in connect_mongodb
rs = db.gmMessageEmail.find().sort({"createTime":-1}).limit(1)
File "D:\Program Files\Python3\lib\site-packages\pymongo\cursor.py", line 873, in sort
keys = helpers._index_list(key_or_list, direction)
File "D:\Program Files\Python3\lib\site-packages\pymongo\helpers.py", line 90, in _index_list
raise TypeError("if no direction is specified, key_or_list must be an instance of list")
TypeError: if no direction is specified, key_or_list must be an instance of list
Are you willing to submit a PR?
- I'm willing to submit a PR! | 我将发起PR!
ZhouYixun commented
很明显pip不是你命令行那个pip,估计用了mac的自带的python2吧,重复的问题可以不用提issue
Ghomeling commented
我这个不是重复的bug,这个bug不是用的mac系统,agent是windows10系统,麻烦帮忙执行下这串代码呢。另外我查了不是用的mac自带的python2,python -version出来的是python3呢。辛苦帮忙瞅瞅呢