使用 resty cli 时出现错误:找不到“resty.http”模块
2020-12-23 8:45:51
收藏:0
阅读:542
评论:2
我在测试使用 resty cli 的示例代码时遇到了问题。 请查看相关命令的输出:
$ which resty
/usr/local/bin/resty
$ which openresty
/usr/local/bin/openresty
$ resty -e 'ngx.say("hello world")'
hello world
文件:test.lua
local http = require "resty.http"
local httpc = http.new()
local res, err = httpc:request_uri("http://example.com/helloworld", {
method = "POST",
body = "a=1&b=2",
headers = {
["Content-Type"] = "application/x-www-form-urlencoded",
},
keepalive_timeout = 60000,
keepalive_pool = 10
})
if not res then
ngx.say("failed to request: ", err)
return
end
使用 resty cli 运行此 test.lua 文件时,我遇到了“找不到”resty.http“模块”的问题:
$ resty test.lua
ERROR: test.lua:1: module 'resty.http' not found:
no field package.preload['resty.http']
no file '/usr/local/Cellar/openresty/1.19.3.1_1/site/lualib/resty/http.ljbc'
no file '/usr/local/Cellar/openresty/1.19.3.1_1/site/lualib/resty/http/init.ljbc'
no file '/usr/local/Cellar/openresty/1.19.3.1_1/lualib/resty/http.ljbc'
no file '/usr/local/Cellar/openresty/1.19.3.1_1/lualib/resty/http/init.ljbc'
no file '/usr/local/Cellar/openresty/1.19.3.1_1/site/lualib/resty/http.lua'
no file '/usr/local/Cellar/openresty/1.19.3.1_1/site/lualib/resty/http/init.lua'
no file '/usr/local/Cellar/openresty/1.19.3.1_1/lualib/resty/http.lua'
no file '/usr/local/Cellar/openresty/1.19.3.1_1/lualib/resty/http/init.lua'
no file './resty/http.lua'
no file '/usr/local/Cellar/openresty/1.19.3.1_1/luajit/share/luajit-2.1.0-beta3/resty/http.lua'
no file '/usr/local/share/lua/5.1/resty/http.lua'
no file '/usr/local/share/lua/5.1/resty/http/init.lua'
no file '/usr/local/Cellar/openresty/1.19.3.1_1/luajit/share/lua/5.1/resty/http.lua'
no file '/usr/local/Cellar/openresty/1.19.3.1_1/luajit/share/lua/5.1/resty/http/init.lua'
no file '/usr/local/Cellar/openresty/1.19.3.1_1/site/lualib/resty/http.so'
no file '/usr/local/Cellar/openresty/1.19.3.1_1/lualib/resty/http.so'
no file './resty/http.so'
no file '/usr/local/lib/lua/5.1/resty/http.so'
no file '/usr/local/Cellar/openresty/1.19.3.1_1/luajit/lib/lua/5.1/resty/http.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file '/usr/local/Cellar/openresty/1.19.3.1_1/site/lualib/resty.so'
no file '/usr/local/Cellar/openresty/1.19.3.1_1/lualib/resty.so'
no file './resty.so'
no file '/usr/local/lib/lua/5.1/resty.so'
no file '/usr/local/Cellar/openresty/1.19.3.1_1/luajit/lib/lua/5.1/resty.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
test.lua:1: in function 'file_gen'
init_worker_by_lua:45: in function <init_worker_by_lua:43>
[C]: in function 'xpcall'
init_worker_by_lua:52: in function <init_worker_by_lua:50>
点赞
用户746559
默认情况下,该库已随 Kong 一起安装。不需要复制文件,可以使用 LUA_PATH 环境变量来调整 Lua 路径设置。这可以使用 LuaRocks(Kong 默认包含)来完成。
使用 LuaRocks 设置路径,请尝试:
eval `luarocks path`
2021-01-06 07:17:12
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?

我使用与 在已安装 openresty 上安装 resty.http 所提到的一样的解决方案解决了它。
第一次,由于我的 resty 路径,它不能工作。 但是当我检查错误日志时,我发现它在
/usr/local/Cellar/openresty/1.19.3.1_1/lualib/resty/http.lua寻找http.lua。 因此,将 https://github.com/ledgetech/lua-resty-http/blob/master/lib/resty/http.lua 复制过去对我有用。感谢 Alexander Altshuler 的 原始答案。