Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

HttpService GET request to Pastebin returns a bunch of nil values (but only sometimes?)

Asked by
Discern 1007 Moderation Voter
5 months ago
Edited 5 months ago

What I'm doing is that I'm using GetAsync() to retrieve a list of userIds from a "paste" I've created on Pastebin. I'm then splitting the userIds into seperate entries into an array.

It appears that it runs perfectly fine about 60% of the time, but however, it just returns a bunch of nil values the other 40% of the time. It appears to be random which happens every time.

Output when it functions properly | Output when it returns nil a bunch of times

Code:

winners = {}

link = "PASTEBIN LINK" -- I have the link to my paste here. The paste is comprised of raw text.

pcall(function() -- try/catch (don't error out)
    text = game:GetService("HttpService"):GetAsync(link, true)
end)

if string.len(text) > 0 then 
    for playerId in string.gmatch(text, "[^\n]+") do -- Split the document into an array containing the strings delimited by all newline characters
        table.insert(winners, tonumber(playerId))
        print(tonumber(playerId))
    end
end

The list contains some userIds separated by newline (with no blank lines or any spaces in between).

Also I'm running this in a regular game server. It doesn't seem to have any trouble when I do it in Test mode in Studio.

Is there a fault in the code I've written? Could it be an issue on Pastebin's side? Any insight would be appreciated. Thanks!

1 answer

Log in to vote
1
Answered by
p0etic 5049 Moderation Voter Community Moderator
5 months ago
Edited 5 months ago

A bit more info about the issue:

Apparently the string OP was getting was HTML for a captcha that pastebin set up to stop people from doing what OP is doing.

It only happened sometimes when you joined a new server, and then continued to happen as long as that server was running. Never had the error happen when we were able to get the text the first time successfully.

Some solutions:

If you want to get around pastebin's captchas, you could always get a pro account.

Reading up on it, there are free workarounds to bypass the captcha, but they're a bit complicated.

We ended up reading from a gituhub instead and didn't have the issue anymore.

0
It turns out that Github caches raw text for a few minutes once you push a new commit so changes won't be reflected instantly in-game since the raw data has to wait to be updated. For requests to be made on occassion over time (like in my scenario) this is fine, but if you're trying to create real-time leaderboards or something, you're probably better off using your own website to store the data. Discern 1007 — 5mo
Ad

Answer this question