This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
karelmikie3's profile picture

wierd crash

Started by karelmikie3, 18 June 2013 - 11:21 AM
karelmikie3 #1
Posted 18 June 2013 - 01:21 PM
my crash is myPastebin:53: attempt to concatenate string and table

code:


local function printUsage()
print( "Usages:" )
print( "myPastebin put <filename> <username>" )
print( "myPastebin get <code> <filename>" )
end
local tArgs = { ... }
if #tArgs < 3 then
printUsage()
   return
end
if not http then
print( "Pastebin requires http API" )
print( "Set enableAPI_http to 1 in mod_ComputerCraft.cfg" )
return
end
local sCommand = tArgs[1]
if sCommand == "put" then
-- Upload a file to pastebin.com
-- Determine file to upload
write("enter your password of pastebin: ")
local pass = read("*")
local sFile = tArgs[2]
local sPath = shell.resolve( sFile )
if not fs.exists( sPath ) or fs.isDir( sPath ) then
  print( "No such file" )
  return
end

-- Read in the file
local sName = fs.getName( sPath )
local file = fs.open( sPath, "r" )
local sText = file.readAll()
file.close()

-- POST the contents to pastebin
write( "Connecting to pastebin.com... " )
local key = "7dac7fda173e56475f19772ece1cf4c6"
local userKey = http.post(
  "http://pastebin.com/api/api_login.php",
  "api_dev_key="..key,
  "api_user_name="..tArgs[3],
  "api_user_password="..pass
  )
local response = http.post(
  "http://pastebin.com/api/api_post.php",
  "api_option=paste&amp;",
  "api_dev_key="..key.."&amp;",
  "api_user_key="..userKey,
  "api_paste_format=lua&amp;",
  "api_paste_name="..textutils.urlEncode(sName).."&amp;"..
  "api_paste_code="..textutils.urlEncode(sText)
  )
 
if response then
  print( "Success." )
 
  local sResponse = response.readAll()
  response.close()
   
  local sCode = string.match( sResponse, "[^/]+$" )
  print( "Uploaded as "..sResponse )
  print( "Run \"pastebin get "..sCode.."\" to download anywhere" )
else
  print( "Failed." )
end

elseif sCommand == "get" then
-- Download a file from pastebin.com
if #tArgs < 3 then
  printUsage()
  return
end
-- Determine file to download
local sCode = tArgs[2]
local sFile = tArgs[3]
local sPath = shell.resolve( sFile )
if fs.exists( sPath ) then
  print( "File already exists" )
  return
end

-- GET the contents from pastebin
write( "Connecting to pastebin.com... " )
local response = http.get(
  "http://pastebin.com/raw.php?i="..textutils.urlEncode( sCode )
  )
 
if response then
  print( "Success." )
 
  local sResponse = response.readAll()
  response.close()
 
  local file = fs.open( sPath, "w" )
  file.write( sResponse )
  file.close()
 
  print( "Downloaded as "..sFile )
 
else
  print( "Failed." )
end
else
printUsage()
return
end
mibac138 #2
Posted 18 June 2013 - 01:41 PM
paste this in pastebin, please :)/>

pastebin says that this line is empty …
karelmikie3 #3
Posted 18 June 2013 - 01:45 PM
here it's on line 51
LBPHacker #4
Posted 18 June 2013 - 02:07 PM
I don't know anything about pastebin's API, but I know that on line 48 (where the actual error is) userKey is not a string but the response handle returned by http.post. Just perform a .readAll on it and close it.