0

I'm trying to create a function that creates an issue to a Github repository using Lua socket.http, but I'm getting connection refused everytime. The documentation for socket is a bit unclear and I couldn't find more helpful information on why is the request getting refused every time. I tried the following:

local config = {
    token = "oauth token from github"
}

local http, ltn12 = require("socket.http"), require("ltn12")
local payload = '{"title": "Test", "body": "Test body", "labels": ["bug"]}'
local response, status, headers, line = http.request("https://api.github.com/repos/<username>/<repository>/issues?access_token=" .. config.token, payload)

So I checked again how to do and there is a second form to do a request. I'm trying the following:

local response = {}
local _, status, headers, line = http.request{
    url = "https://api.github.com/repos/<username>/<repository>/issues",
    sink = ltn12.sink.table(response),
    method = "POST",
    headers = {
        ["Authorization"] = "token " .. config.token,
        ["Content-Length"] = payload:len()
    },
    source = ltn12.source.string(payload)
}

According to socket documentation, this should make POST request to the URL sending the payload as body. If I print(status) it prints connection refused.

I'm ignoring the first return value as it always is 1.

I tried manually issuing the request using curl:

curl -H "Authorization: token <oauth token from github>" https://api.github.com/repos/<username>/<repository>/issues -XPOST -d '{"title": "Test", "body": "{"title": "Test", "body": "Test body", "labels": ["bug"]}'

And it posted the issue properly. I still can't figure it out what is happening that the connection is getting refused.

ranieri
  • 2,030
  • 2
  • 21
  • 39
  • Do you have something (like luasec) that can handle the ssl part of `https`? Like in [this question](http://stackoverflow.com/q/8286677/258523)? – Etan Reisner Jul 16 '15 at 22:51
  • No, I wasn't. I downloaded and compiled luasec and using it says `/usr/lib/lua/5.1/ssl.so: undefined symbol: luaL_setfuncs` and it doesn't work. I'm using Lua 5.1 through LuaJIT 2.0.4. – ranieri Jul 16 '15 at 23:05
  • `luaL_setfuncs` is a lua 5.2+ function. You compiled luasec against lua 5.2 or 5.3 and then installed it in a lua 5.1 directory it sounds like. – Etan Reisner Jul 17 '15 at 00:06
  • No, not really. Lua version is set to 5.1 on luasec makefile and I only have 5.1 on my computer. – ranieri Jul 17 '15 at 05:52
  • Can you show the compilation command that make ran for luasec? Can you run `nm /usr/lib/lua/5.1/ssl.so`? – Etan Reisner Jul 17 '15 at 15:26

0 Answers0