How to load LUA modules in aquarium/scrapy-splash? - lua

I am working on a LUA script for scrapy-splash and want to use the socket.http module.
The module is installed, I have disabled the sandbox and configured the package path. But I can't get it to work.
My environment is aquarium on Linux.
I have installed luasocket using luarocks and added
--disable-lua-sandbox --lua-package-path "/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/?.lua"
to the splash instance in docker-compose.yml.
When I run the script I get the following error:
"error": {"info": {"type": "LUA_INIT_ERROR", "message": "[string \"<python>\"]:1: module 'socket.http' not found:
no field package.preload['socket.http']
no file '/app/splash/lua_modules/socket/http.lua'
no file '/app/splash/lua_modules/libs/socket/http.lua'
no file '/usr/local/share/lua/5.1/socket/http.lua'
no file '/usr/local/share/lua/5.1/socket/http/socket/http.lua'
no file '/usr/local/share/lua/5.2/socket/http.lua'
no file '/usr/local/share/lua/5.2/socket/http/init.lua'
no file '/usr/local/lib/lua/5.2/socket/http.lua'
no file '/usr/local/lib/lua/5.2/socket/http/init.lua'
no file '/usr/share/lua/5.2/socket/http.lua'
no file '/usr/share/lua/5.2/socket/http/init.lua'
no file './socket/http.lua'
no file '/usr/local/lib/lua/5.2/socket/http.so'
no file '/usr/lib/x86_64-linux-gnu/lua/5.2/socket/http.so'
no file '/usr/lib/lua/5.2/socket/http.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './socket/http.so'
no file '/usr/local/lib/lua/5.2/socket.so'
no file '/usr/lib/x86_64-linux-gnu/lua/5.2/socket.so'
no file '/usr/lib/lua/5.2/socket.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './socket.so'"}, "description": "Error happened while executing Lua script", "type": "ScriptError", "error": 400}, "qsize": 0, "status_code": 400}
Even though the file /usr/local/share/lua/5.1/socket/http.lua exists on my machine. I have also tried to chmod 777 the file but it still throws the error.

It turned out that there was no need for me to use socket.http.
I am using splash:http_get and splash:http_post now and it is working fine.

Related

issue with XmlFileLoader.php XmlUtils.php

When running symfony inside a docker container, there is this issue
// Clearing the cache for the dev environment with debug
// true
In XmlFileLoader.php line 407:
Unable to parse file "/www/xxx/vendor/symfony/monolog-bundle/Depende
ncyInjection/../Resources/config/monolog.xml": The XML file "/www/xxx/vendor/symfony/monolog-bundle/DependencyInjection/../Resources/config/mon
olog.xml" is not valid.
In XmlUtils.php line 148:
The XML file "/www/xxx/vendor/symfony/monolog-bundle/DependencyInjec
tion/../Resources/config/monolog.xml" is not valid.
In XmlFileLoader.php line 684:
Notice: tempnam(): file created in the system's temporary directory
cache:clear [--no-warmup] [--no-optional-warmers]
What is the issue and how to resolve it.
Thanks

OpenResty: not found 'socket' module

I install lua socket module by run the following command:
apt install lua-socket
When use local socket = require('socket') in OpenResty config, I got the following error:
module 'socket' not found:
no field package.preload['socket']
no file '/usr/local/openresty/site/lualib/socket.ljbc'
no file '/usr/local/openresty/site/lualib/socket/init.ljbc'
no file '/usr/local/openresty/lualib/socket.ljbc'
no file '/usr/local/openresty/lualib/socket/init.ljbc'
no file '/usr/local/openresty/site/lualib/socket.lua'
no file '/usr/local/openresty/site/lualib/socket/init.lua'
no file '/usr/local/openresty/lualib/socket.lua'
no file '/usr/local/openresty/lualib/socket/init.lua'
no file './socket.lua'
no file '/usr/local/openresty/luajit/share/luajit-2.1.0-beta3/socket.lua'
no file '/usr/local/share/lua/5.1/socket.lua'
no file '/usr/local/share/lua/5.1/socket/init.lua'
no file '/usr/local/openresty/luajit/share/lua/5.1/socket.lua'
no file '/usr/local/openresty/luajit/share/lua/5.1/socket/init.lua'
no file '/usr/local/openresty/site/lualib/socket.so'
no file '/usr/local/openresty/lualib/socket.so'
no file './socket.so'
no file '/usr/local/lib/lua/5.1/socket.so'
no file '/usr/local/openresty/luajit/lib/lua/5.1/socket.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
OpenResty Version: 1.19.3.1
How can use socket module in OpenResty?
I think https://github.com/thibaultCha/lua-resty-socket should be used in openresty ecosystem.

Why lua require won't search current directory?

say I've two files test.lua and m.lua in a folder, in test.lua as:
require("m")
then I run this file, howerver it raise an error:
lua: /Users/xx/works/scripts/test.lua:43: module 'm' not found:
no field package.preload['m']
no file '/usr/local/share/lua/5.3/m.lua'
no file '/usr/local/share/lua/5.3/m/init.lua'
no file '/usr/local/lib/lua/5.3/m.lua'
no file '/usr/local/lib/lua/5.3/m/init.lua'
no file './m.lua'
no file './m/init.lua'
no file '/usr/local/lib/lua/5.3/m.so'
no file '/usr/local/lib/lua/5.3/loadall.so'
no file './m.so'
As you can see the line no file './m.lua' appears but this is not true. ./m.lua exists, and file permission stuff is OK. If I hardcode the path:
package.path = package.path..';'..'/Users/xx/works/scripts/?.lua'
require('m')
It will work as expected.
What should I do to make lua search current directory fisrt (like python's import) when require a module
The current directory is the directory where you launch lua from.
The command line is missing in your example, if you used lua test.lua then it shoud work, if you used lua works/scripts/test.lua then it will not work.

How To Require Lua Socket?

I'm very new to lua development with file manipulation, and now trying to import the lua socket package into my project according to this post, but I can't run even the code below.
I guess the error message indicates I need to import not only the socket.lua but also .\socket\core (probably .dll, since it doesn't have core.lua), while a reply at the post suggested importing only the file.
I'm stuck in just the beginning... What do I have to do for the next step?
local function main()
local socket = require("socket")
end
main()
Exception in thread "main" com.naef.jnlua.LuaRuntimeException: ...n32.win32.x86_64\workspace\TestForCiv\src\socket.lua:13: module 'socket.core' not found:
no field package.preload['socket.core']
no file '.\socket\core.lua'
no file 'C:\Program Files\Java\jre1.8.0_151\bin\lua\socket\core.lua'
no file 'C:\Program Files\Java\jre1.8.0_151\bin\lua\socket\core\init.lua'
...(a bunch of no file errors continues)
Edit: I added the folder structure. Even I add the .dll file it returns the same error.
I don't know the details of you configuration, but try this
require ("src.socket")
you should require a module from the root path of the lib

Using tdbloader.bat to upload a RDF file and querying using tdbquery.bat

I want to upload an RDF file using tdbloader.bat (C:\apache-jena-2.10.0\bat, in my case).
My turtle file is located in C:\apache-jena-2.10.0, and is named test.ttl. What will be the command line to load the turtle file using tdbloader.bat? After it is loaded, what would be a command line to query with tdbquery.bat?
I have used the following command-
tdbloader.bat -loc c:\apache-jena-2.10.0 test.ttl
But it returned a FileNotFound Exception.
The file test.ttl isnt in the same directory as bat files which is causing FileNotFound exception. A correction would be to copy test.ttl to C:\apache-jena-2.10.0\bat. After doing that execute command
tdbloader.bat -loc potato test.ttl.
This would load test.ttl to a folder named potato in same directory as tdbloader.bat. Hope it helps

Resources