Jump to content




http.get returns nil


  • You cannot reply to this topic
8 replies to this topic

#1 houseofkraft

  • Members
  • 170 posts
  • LocationUSA

Posted 13 September 2016 - 11:13 AM

Hi Guys!

I am currently working on the auto updater for CarbonOS again. It is so good! No more problems except one. http.get returns nil for some reason. I think the URL is correct. I even copied and pasted the Raw URL and it still returns nil.

Code:
local nextFile = "/.os"
local files = {
    [1] = {
	    "/System/Images/boot",
	    "https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/System/Images/boot"
    },
    [2] = {
	    "startup",
	    "https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/startup"
    },
    [3] = {
	    "/Programs/LuaIDE/program",
	    "https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/Programs/LuaIDE/program"
   },
   [4] = {
	   "/Programs/Sketch/program",
	   "https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/Programs/Sketch/program"
   },
   [5] = {
	   "/Desktop/LuaIDE",
	   "https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/Desktop/LuaIDE"
  },
  [6] = {
	  "/Desktop/Sketch",
	  "https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/Desktop/Sketch"
  },
  [7] = {
	  "/System/Images/desktop",
	  "https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/System/Images/desktop"
},
[8] = {
	 "/System/settings",
	 "https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/System/settings"
},
[9] = {
	 "/System/autoupdater",
	 "https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/System/autoupdater"
},
[10] = {
	  "/System/.version",
	  "https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/System/.version"
},
[11] = {
	  "/os",
	  "https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/os"
}
}
remoteVersion = http.get("https://raw.githubusercontent.com/Carbon-OS/CarbonOS/master/System/.version")
local localVersion = fs.open("System/.version", "r")
local currentVer = localVersion.readAll()
local rVersion = remoteVerion.readAll()
local lVersion = localVersion.readAll()
localVersion.close()
if rVersion ~= lVersion then
    print("Downloading Update...")
    print("Your Verison: ", lVersion)
    print("New Version: ", rVersion)
    for k, v in pairs(files) do
	    local currentFile = fs.open(v[1], "w")
	    local remoteFile = http.get(v[2])
	    if remoteFile ~= nil then
		    currentFile.write(remoteFile.readAll)
	    end
	    currentFile.close()
	    remoteFile.close()
    end
end
local next = fs.open(nextFile, "r")
pcall(loadstring(next.readAll()))
--Put code to run if the os crashes

If you would like to fix it, you can tell me or create a pull request (the easiest way is to create a pull request)
Github: https://github.com/C...autoupdater#L49

The highlighted line is the http.get that returns nil

Thank You!

#2 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 13 September 2016 - 11:24 AM

Are you using an emulator? That may be the problem, as I cannot replicate this.

Posted Image

#3 houseofkraft

  • Members
  • 170 posts
  • LocationUSA

Posted 13 September 2016 - 11:33 AM

Im not using an emulator. Btw the content of the .version file says 1 if that helps

EDIT: I did an http.checkURL and it said that the url is correct

Edited by houseofkraft, 13 September 2016 - 11:37 AM.


#4 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 13 September 2016 - 11:58 AM

What version of computercraft are you using? Does your config allow http? As you can see in my screenshot, http.get works perfectly fine on that url for me.

#5 houseofkraft

  • Members
  • 170 posts
  • LocationUSA

Posted 13 September 2016 - 12:00 PM

Im using CC 1.74 with the HTTP API enabled

#6 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 13 September 2016 - 12:15 PM

Are you absolutely certain it is http.get that is returning nil? Remember, computercraft errors sometimes are off by one line number.

#7 houseofkraft

  • Members
  • 170 posts
  • LocationUSA

Posted 13 September 2016 - 12:21 PM

I'm not too sure because someone told me on the server yesterday that the http.get is returning nil. Because I get an attempt to call nil error when it displays the current version and the new version

#8 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 13 September 2016 - 01:04 PM

Perhaps it has something to do with the fact that you are using .readAll on the same file handle twice? I'm unsure as to what the effects of that would be.

#9 apemanzilla

  • Members
  • 1,421 posts

Posted 13 September 2016 - 01:41 PM

View PostKingofGamesYami, on 13 September 2016 - 01:04 PM, said:

Perhaps it has something to do with the fact that you are using .readAll on the same file handle twice? I'm unsure as to what the effects of that would be.

That would probably be why, after the handle is read it can't be read again IIRC.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users