首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >jsonpath python模块:模块'jsonpath‘没有属性'jsonpath’

jsonpath python模块:模块'jsonpath‘没有属性'jsonpath’
EN

Stack Overflow用户
提问于 2017-06-05 17:43:16
回答 0查看 492关注 0票数 0

我在脚本中使用相同的python代码,并在cli中直接使用。虽然在cli中代码没有错误,但在脚本中它给了我一个错误。

代码语言:javascript
复制
AttributeError: module 'jsonpath' has no attribute 'jsonpath'

代码:

代码语言:javascript
复制
import os
import click
import subprocess
import urllib.request
import json
import jsonpath

@cli.command()
@click.argument('search', required=False, nargs=-1)
def search(search):
    for srch in search:
        packs = urllib.request.urlopen("https://aur.archlinux.org//rpc/?v=5&type=search&arg="+srch).read()
        somejson = json.loads(packs)
        match = jsonpath.jsonpath(somejson, '$.results[*].Name,Version,Description')
        print(match)

对于cli和脚本,我使用相同的virtualenv。

代码cli:

代码语言:javascript
复制
(venv) [user@laptop pyapp]$ python
Python 3.6.1 (default, Mar 27 2017, 00:27:06) 
[GCC 6.3.1 20170306] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import jsonpath
>>> import json
>>> import urllib.request
>>> jsontext = urllib.request.urlopen("https://aur.archlinux.org//rpc/?v=5&type=search&arg=teamviewer").read()
>>> somejson = json.loads(jsontext)
>>> match = jsonpath.jsonpath(somejson, '$.results[*].Name,Version,Description')
>>> print(match)
['teamviewer-quicksupport-beta', '11.0.52520-1', 'Teamviewer Quicksupport - All-In-One Software for Remote Support and Online Meetings - beta version', 'teamviewer10', '10.0.46203-1.1', 'All-In-One Software for Remote Support and Online Meetings', 'remmina-plugin-teamviewer', '1.2.3.0-1', 'A protocol plugin for Remmina to launch a TeamViewer connection.', 'teamviewer8', '8.0.20931-1', 'All-In-One Software for Remote Support and Online Meetings', 'teamviewer-quicksupport', '11.0.57095-2', 'Teamviewer Quicksupport - All-In-One Software for Remote Support and Online Meetings', 'teamviewer-openrc', '1.0-2', 'OpenRC scripts for teamviewer.', 'teamviewer-beta', '12.0.69753-1', 'All-In-One Software for Remote Support and Online Meetings - beta version', 'teamviewer11', '11.0.67687-1', 'All-in-one software for remote support and online meetings', 'teamviewer9', '9.0.32150-1', 'All-In-One Software for Remote Support and Online Meetings', 'teamviewer', '12.0.76279-6', 'All-In-One Software for Remote Support and Online Meetings']

我不明白代码出了什么问题。完整的代码是here

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44366048

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档