小编pro*_*oob的帖子

如何从Node-Red触发Raspberry Pi上的Python脚本

我正在使用Node-Red,在Raspberry Pi上托管一个物联网项目.

如何从Node-Red触发raspi上的Python脚本?我想运行一个脚本来更新位于Pi上的Adafruit LCD屏蔽上的文本

我是否应该以某种方式将Python脚本公开为Web服务?

我正在使用Raspberry Pi B +

python gpio raspberry-pi node-red iot

6
推荐指数
1
解决办法
2万
查看次数

使用机架中间件捕获无效的JSON解析错误

我正在使用Rails 5,我正在尝试改进对我的API的无效JSON请求的错误处理.

我尝试通过在控制器中进行解析来处理无效格式JSON,但是如果用户将内容类型添加到其请求头中,则意识到Rails中间件在它到达控制器之前解析我的JSON请求.

我按照以下指南:https: //robots.thoughtbot.com/catching-json-parse-errors-with-custom-middleware

但是,启动服务器时出现以下错误:

.rbenv/versions/2.3.1/lib/ruby​​/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/stack.rb:108:在`assert_index'中:没有这样的中间件要插入之前:ActionDispatch :: ParamsParser(RuntimeError)

现在,这意味着ActionDispatch :: ParamsParser没有运行.我认为它在Rails 5中已被弃用,因此排除了该选项.

我还尝试在我的API控制器中使用rescue_from:

rescue_from JSON::ParserError, with: :json_error

def json_error
  render status: 400, json: {error: "Invalid JSON format in request body"}, status: :unprocessable_entity
end
Run Code Online (Sandbox Code Playgroud)

但是,这也没有用.它似乎跳过了它.

或者如果我试试这个:

rescue_from JSON::ParserError, with: json_error

def json_error
  render status: 400, json: {error: "Invalid JSON format in request body"}, status: :unprocessable_entity
end
Run Code Online (Sandbox Code Playgroud)

我明白了:

undefined local variable or method `json_error' for Api::ApiController:Class
actionpack (5.0.0.1) lib/action_dispatch/routing/route_set.rb, line 46

``` ruby
   41         private
   42   
   43           def controller(req) …
Run Code Online (Sandbox Code Playgroud)

ruby json ruby-on-rails ruby-on-rails-5

6
推荐指数
1
解决办法
2406
查看次数

Bot提及的Slack事件API

我正在使用Slack App构建一个Slack bot.我已设法通过Event API授权并成功接收事件.

我试图找出如何只听直接提到的机器人.

因此,当有人向公共或私人频道发送消息时以及当机器人被直接标记为@bot时,它应该触发事件

公共/私人Slack Channel示例:

Daniel: Hi there bot        (does not trigger)
Jeremy: @bot hi there       (triggers Event API)
Run Code Online (Sandbox Code Playgroud)

是否有松弛事件这样做?或者还有另一种方法吗?我不想将其硬编码到我的服务器端应用程序中,因为那时我将收到很多不必要的事件.

slack-api slack

2
推荐指数
1
解决办法
3651
查看次数