Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Invalid] Python-调用mongodb功能无法使用 #419

Open
2 tasks done
Ghomeling opened this issue Mar 12, 2024 · 2 comments
Open
2 tasks done

[Invalid] Python-调用mongodb功能无法使用 #419

Ghomeling opened this issue Mar 12, 2024 · 2 comments
Labels
invalid This doesn't seem right

Comments

@Ghomeling
Copy link

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

  1. 自定义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()

  1. python直接本地执行是ok的,但是用sonic的自定义代码执行就会失败:
    image
    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!
@Ghomeling Ghomeling added the bug Something isn't working label Mar 12, 2024
@ZhouYixun
Copy link
Member

很明显pip不是你命令行那个pip,估计用了mac的自带的python2吧,重复的问题可以不用提issue

@ZhouYixun ZhouYixun changed the title [Bug] Python-调用mongodb功能无法使用 [Invalid] Python-调用mongodb功能无法使用 Mar 12, 2024
@ZhouYixun ZhouYixun added invalid This doesn't seem right and removed bug Something isn't working labels Mar 12, 2024
@Ghomeling
Copy link
Author

Ghomeling commented Mar 12, 2024

我这个不是重复的bug,这个bug不是用的mac系统,agent是windows10系统,麻烦帮忙执行下这串代码呢。另外我查了不是用的mac自带的python2,python -version出来的是python3呢。辛苦帮忙瞅瞅呢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants