Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I fix http 401 (http/1.1 401 unauthorized)?

Asked by 7 years ago
Edited 7 years ago

Hello, I was wondering how I fix this error. Here's the error http 401 (http/1.1 401 unauthorized)

Here's the script:

local board = "GHJ4Iw8A" 

--------------------------------------------------------------------------------------------------------------------------------------------------------------

local Songs = {}



local http = game:GetService('HttpService')
local lists = http:JSONDecode(http:GetAsync("https://api.trello.com/1/boards/"..board.."/lists"))
for _,v in pairs(lists) do
    if v.name == "Music List" then
        local items = http:JSONDecode(http:GetAsync("https://api.trello.com/1/lists/"..v.id.."/cards"))
        print(#items)
        for _,v in pairs(items) do
            if v.name:match(":") ~= nil then
                local s,f = string.find(v.name,":")
                table.insert(Songs, string.sub(v.name,f+1)) 
            end
        end
    end
end

math.randomseed( os.time() )

_G.Skip = function()
    if workspace:FindFirstChild("Sound") ~= nil then
        workspace.Sound:Stop()
    end
end


function shuffleTable(t)
    math.randomseed(tick())
    assert(t, "shuffleTable() expected a table, got nil" )
    local iterations = #t
    local j
    for i = iterations, 2, -1 do
        j = math.random(i)
        t[i], t[j] = t[j], t[i]
    end
end


shuffleTable(Songs)

local songnum = 0


game.Players.PlayerAdded:connect(function(p)
    if p:GetRankInGroup(2833043) >= 40 or p.Name == "Player1" then
        p.Chatted:connect(function(msg)
            if string.lower(msg) == ":skipsong" then
                _G.Skip()
                spawn(function()
                    local h = Instance.new("Hint", p.PlayerGui)
                    h.Text = "Audio skipped."
                    wait(5)
                    h:Destroy()
                end)
            end
        end)
    end
end)

local Market = game:GetService("MarketplaceService")

local PlayerChosen = {}
local NotPlaying = false
local LastSong;
local SongNum = 0

while wait() do     
    SongNum = SongNum+1
    local RawSong = Songs[SongNum]
    local Song = "http://www.roblox.com/asset/?id="..Songs[SongNum]
    if Song ~= LastSong then
        game:GetService("ContentProvider"):Preload(Song)
        local Sound = Instance.new("Sound", game.Workspace)
        Sound.Volume = 1
        Sound.SoundId = Song
        Sound:Play()
        game.ReplicatedStorage.Events.SongChanged:FireAllClients(game:service('MarketplaceService'):GetProductInfo(tonumber(RawSong)).Name)
        wait(120)
        Sound:Stop()
        wait()
        Sound:remove()
        NotPlaying = false
    else
        NotPlaying = false          
    end
end 
0
Request denied usually means that you did not send credentials. Make sure you take a look at the Trello api for examples on how to send requests with proper authentication (the website won't trust just any request). Maybe make your board publicly visible? User#18718 0 — 7y

1 answer

Log in to vote
0
Answered by 5 years ago

The reason you get a 401 error is you did not supply an app key.

First, log into your Trello account at http://trello.com/. Then, go to https://trello.com/1/appKey/generate. You should see a screen like this: !API Key screen Copy that code (Ctrl+C)! Then, add the following to each of the URLs you are requesting:

?key=REPLACE WITH YOUR KEY

Try it, it should work perfectly now!

Ad

Answer this question