我有个问题.我正在编写一个软件,它需要执行一个操作,要求用户处于sudo模式.运行'sudo python filename.py'不是一个选项,这引出了我的问题.有没有办法在python脚本的一半更改为sudo,安全性不是问题,因为用户将通过以下方式知道程序应该运行的sudo密码来说明问题
我的问题在于第3步,你可以建议的任何指针或框架都会有很大的帮助.
干杯
克里斯
我一直在和reactjs合作,并且认为我开始玩graphql和relay.我遇到了一个我无法触及的错误,所以我想知道这里是否有人遇到过同样的错误.任何指针或想法都会受到欢迎.
我得到的错误是
Error: GraphQL validation/transform error ``Object has no method 'find'`` in file `/Users/chris/Documents/App/site/js/main.js`.
Run Code Online (Sandbox Code Playgroud)
所以我有一个GraphQL服务器正在运行,一切正常我可以查询后端数据库(我正在使用mongodb),以下查询通过graphql ui生成正确的结果
{
store{
items{
_id
title
sub
}
}
}
produces the following output which is correct
{
"data": {
"store": {
"items": [
{
"_id": "56e2c71d150040c491c73b26",
"title": "Test Item One",
"sub": "sub title here"
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
所以我认为可以安全地假设graphql服务器很好,问题必须是我的relay或babelRelayPlugin.js的实现
以下是main.js文件,其中简化了render方法.
import React from 'react';
import Relay from 'react-relay';
class Main extends React.Component {
render(){
return (
<div>
<p>Test</p>
</div>
);
}
}
Main …Run Code Online (Sandbox Code Playgroud) 我有一个问题,应该是一个基本的概念在cherrypy但是我一直无法找到关于如何做到这一点的教程或例子(我是一个Cherrypy新手,温柔).
问题.(这是一个测试部分,因此代码中缺乏强大的身份验证和会话)
用户转到index.html页面,该页面是登录页面,用于输入详细信息,如果详细信息与文件中的内容不匹配,则会返回并显示错误消息.这有效!如果细节是正确的,那么向用户显示不同的html文件(network.html)这是我无法工作的一点.
当前的文件系统如下所示: -
AppFolder
- main.py (main CherryPy file)
- media (folder)
- css (folder)
- js (folder)
- index.html
- network.html
Run Code Online (Sandbox Code Playgroud)
文件的布局似乎是正确的,因为我可以访问index.html代码看起来像这样:(我在我试图返回新页面时放置了注释)
import cherrypy
import webbrowser
import os
import simplejson
import sys
from backendSystem.database.authentication import SiteAuth
MEDIA_DIR = os.path.join(os.path.abspath("."), u"media")
class LoginPage(object):
@cherrypy.expose
def index(self):
return open(os.path.join(MEDIA_DIR, u'index.html'))
@cherrypy.expose
def request(self, username, password):
print "Debug"
auth = SiteAuth()
print password
if not auth.isAuthorizedUser(username,password):
cherrypy.response.headers['Content-Type'] = 'application/json'
return simplejson.dumps(dict(response ="Invalid username and/or password"))
else:
print "Debug 3"
#return …Run Code Online (Sandbox Code Playgroud) 我目前正在开发一个我们之前使用Django的项目.然而,这对我们的需求来说有点重量级,因此我们正在将项目转移到使用cherrypy,因为我们只需要处理请求.
我的问题是这个.我在html页面(index.html)上有一个表单,当用户点击提交时,执行以下jQuery函数.
$(document).ready(function() {
$("#loginform").submit(function() {
var request_data = {username:$("#username").val(),password:"test"};
$.post('/request',request_data, function(data) {
$("#error").html(data['response']);
});
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
这很好用.以下Cherrypy方法应该获取请求数据,但似乎没有执行.这是请求的Cherrypy方法.
@cherrypy.expose
def request(self, request_data):
print "Debug"
cherrypy.response.headers['Content-Type'] = 'application/json'
return simplejson.dumps(dict(response ="Invalid username and/or password"))
Run Code Online (Sandbox Code Playgroud)
这只是一种测试方法,我希望在终端窗口中看到"Debug",并在点击提交按钮后显示在网页上的错误消息
在终端中,我在收到请求后收到此消息:
"POST /request HTTP/1.1" 404 1254 "http://127.0.0.1:8080/" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; en-us) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1"
Run Code Online (Sandbox Code Playgroud)
这表明它找不到请求方法.我只能想到它与参数有关.
由于我是新手,我希望它是一个简单的东西,我错过任何指针都会很棒.
PS:以下工作,但我需要能够将多个数据传递给cherrypy.(cherrypy参数更改为用户名以允许此操作)
$(document).ready(function() {
$("#loginform").submit(function() {
$.post('/request',{username:$("#username").val()}, function(data) {
$("#error").html(data['response']);
});
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
在此问题上提前感谢您提供任何帮助或指导.
这是我的完整樱桃文件.
import cherrypy
import webbrowser …Run Code Online (Sandbox Code Playgroud)