Announcement

Collapse

Forum Rules

  • No flaming or derogatory remarks, directly or through insinuation.
  • No discussion, sharing or referencing illegal software such as hacks, keygen, cracks and pirated software.
  • No offensive contents, including but not limited to, racism, gore or pornography.
  • No excessive spam/meme, i.e. copious one liners in a short period of time, typing with all caps or posting meme responses (text/image).
  • No trolling, including but not limited to, flame incitation, user provocation or false information distribution.
  • No link spamming or signature advertisements for content not specific to Dota 2.
  • No Dota 2 key requests, sell, trade etc.
  • You may not create multiple accounts for any purpose, including ban evasion, unless expressly permitted by a moderator.

  • Please search before posting. One thread per issue. Do not create another thread if there is an existing one already.
  • Before posting anything, make sure you check out all sticky threads (e.g., this). Do not create new threads about closed ones.
  • It is extremely important that you post in correct forum section.

  • Balance discussion only in Misc.
  • All art related (such as hero model) feedbacks go to Art Feedback Forum.
  • All matchmaking feedback should go here: Matchmaking Feedback
  • All report/low priority issues should go here: Commend/Report/Ban Feedback
  • No specific workshop item feedback. These should go to workshop page of that item.
  • When posting in non-bugs section (such as this), use [Bugs], [Discussion] or [Suggestion] prefix in your thread name.



In case you object some action by a moderator, please contact him directly through PM and explain your concerns politely. If you are still unable to resolve the issue, contact an administrator. Do not drag these issues in public.



All rules are meant to augment common sense, please use them when not conflicted with aforementioned policies.
See more
See less

anyone managed to use CreateHTTPRequest?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • anyone managed to use CreateHTTPRequest?

    I have tried almost every implementation of this I can think of and have got none to work.

    If anyone has a working example I would be very grateful if someone could share so I can see if I'm doing anything wrong
    https://github.com/ThePianoDentist/t...dentistdotabot Lina bot which pulls small camp when 'laning' (Aim to work on pulling and stacking bots initially)
    https://github.com/ThePianoDentist/dotabots-ml-tools Parsing data from bot games

  • #2
    think I found my issue


    FmtStrVSNPrintf truncated to 256 without QUIET_TRUNCATION specified! String
    "http://localhost/:9200/doublepull/run?{"type":"parameter_values","values":{"damage_s pread_lane":0,"damage_spread_neutral":0,"fraction_ lane_left":0,"fraction_neutral_left":1.25,"hero_at tackdamage":53,"hero_attackrange":670,"hero_attack speed":1.20000004768"

    whilst doing
    Code:
    CreateHTTPRequest(":9200/doublepull/run?" ..tostring(JSON:encode(data)))
    so a) you cannot specify a port as the method hard-codes a slash after localhost
    b) it appears you can only send very, very short snippets of data. max length 256

    edit: I have no idea how I saw these errors. 99/100 times it just fails silently. guess I just got lucky 0_o
    Last edited by TheP1anoDentist; 03-11-2017, 11:34 AM.
    https://github.com/ThePianoDentist/t...dentistdotabot Lina bot which pulls small camp when 'laning' (Aim to work on pulling and stacking bots initially)
    https://github.com/ThePianoDentist/dotabots-ml-tools Parsing data from bot games

    Comment


    • #3
      ...well still doesn't work.

      the exact string I am giving to CreateHTTPRequest is doublepull/run?data={"dsl":0,"dsn":0,"fll":0.6,"fnl":0.75,"ha ":50,"hm":295,"lteh":1532,"nteh":1440.54,"s":true, "tleh":0,"tneh":0}

      i've ditched the port after setting my elasticsearch to run on port 80

      `curl localhost` successfully points towards elasticsearch and returns fine. therefore has to be an issue with CreateHTTPRequest
      https://github.com/ThePianoDentist/t...dentistdotabot Lina bot which pulls small camp when 'laning' (Aim to work on pulling and stacking bots initially)
      https://github.com/ThePianoDentist/dotabots-ml-tools Parsing data from bot games

      Comment


      • #4
        if this does get fixed. Can I pre-emptively ask to also be able to specify data for POST request in request body, not just as url arguments.
        I believe the CreateHTTPRequest for custom games already has this.

        Also this may be the most sensible way to remove the max-length issue if you have a large request to send (more than 256 chars)


        (my implementation for using this data I think I've realised cant work with url arguments I can change but it'd be nice for it to just work)
        https://github.com/ThePianoDentist/t...dentistdotabot Lina bot which pulls small camp when 'laning' (Aim to work on pulling and stacking bots initially)
        https://github.com/ThePianoDentist/dotabots-ml-tools Parsing data from bot games

        Comment


        • #5
          Can you post your entire call to the code?

          I'll also up the maximum length of the string to 8k.

          Comment


          • #6
            Not my thread, but:

            Code:
            print(CreateHTTPRequest(""))
            will print nil all the time, although I have a server running on port 80 (ncat -l 127.0.0.1 80, to be precise).
            It's a somewhat minimalistic example, but from what I read it should still work.

            Edit: Just came to mind: Could there be something wrong with "localhost" on windows systems? I believe I had some minor issues with that in the past. Not sure.
            Last edited by Justus Mea; 03-28-2017, 06:33 AM.

            Comment


            • #7
              Ah, I see the issue, dumb oversight on my part.

              Comment


              • #8
                Originally posted by ChrisC View Post
                Ah, I see the issue, dumb oversight on my part.
                Has this been fixed? I'm getting a non-nil return now, as in it returns a table with a single key, value:
                Code:
                [VScript] __self	userdata: 0x00245400
                But doing a Send via:
                Code:
                        local req = CreateHTTPRequest("")
                        if req then
                            req:Send(function(res)
                                print(res)
                            end)
                        end
                Doesn't seem to hit the cherrypy server I have running on localhost:80 that I can browse to no problem

                also apparently there is an issue with Send() - traceback:
                Code:
                [VScript] Script Runtime Error: attempt to call a table value
                stack traceback:
                So my understanding is that the CreateHTTPResponse object will have the asynchronous Send() function which should take a callback function as an argument...
                Last edited by nostrademous; 04-05-2017, 09:43 PM.

                Comment


                • #9
                  CreateHTTPRequestScriptVM (mind that they just renamed it) takes two parameters, the method ("POST", "GET") and the Url:

                  Code:
                  request = CreateHTTPRequestScriptVM( "GET", myUrl)
                  request:Send( function( result ) 
                                -- do whatever
                  end )

                  Comment


                  • #10
                    Originally posted by Lightbringer View Post
                    CreateHTTPRequestScriptVM (mind that they just renamed it) takes two parameters, the method ("POST", "GET") and the Url:

                    Code:
                    request = CreateHTTPRequestScriptVM( "GET", myUrl)
                    request:Send( function( result ) 
                                  -- do whatever
                    end )
                    I believe that's for modding only, not available via the bot-scripting API. The Bot Scripting API is CreateHTTPRequest( sParam ) that only takes 1 parameter as @ChrisC wanted to force only allowing a "POST" and only to "http://localhost". Perhaps he added the second parameter as "http://localhost/" with the extra "/" at end prevent us from specifying port of our choosing, not sure.

                    Comment


                    • #11
                      Okay, I managed to get the webserver to see the POST messages... but the Send( callbackArg ) which I expect to be a function ptr doesn't seem to work.

                      Comment


                      • #12
                        Originally posted by nostrademous View Post
                        I believe that's for modding only, not available via the bot-scripting API. The Bot Scripting API is CreateHTTPRequest( sParam ) that only takes 1 parameter as @ChrisC wanted to force only allowing a "POST" and only to "http://localhost". Perhaps he added the second parameter as "http://localhost/" with the extra "/" at end prevent us from specifying port of our choosing, not sure.
                        I was indeed quoting from the modding API, as google brought me into this thread as my own Bot framework broke due to the signature change. I didn't look much into the bot scripting as the lack of the HTTP calls made it uninteresting for me. Guess that change it's what this is all about. Thanks for making me aware of this.

                        Comment


                        • #13
                          Here is my super simple bot code that "almost" works..

                          bot_<heroName>.lua:
                          Code:
                          local lastUpdate = -1000.0
                          local data = {}
                          
                          function Think()
                              local bot = GetBot()
                          
                              data["test"] = {Health = bot:GetHealth(), MaxHealth = bot:GetMaxHealth()}
                              
                              if GameTime() - lastUpdate > 2.0 then
                                  lastUpdate = GameTime()
                                  
                                  local json = '{"data":{'
                                  local count = 1
                                  for key, value in pairs(data["test"]) do
                                      if count > 1 then json = json..',' end
                                      json = json .. '"' .. key .. '": ' .. value
                                      count = count + 1
                                  end
                                  json = json..'}}'
                                  
                                  print(tostring(json))
                                  
                                  local req = CreateHTTPRequest( "" )
                                  req:SetHTTPRequestRawPostBody("application/json", json)
                                  req:Send( function( result )
                                      print( "GET response:\n" )
                                      for k,v in pairs( result ) do
                                          print( string.format( "%s : %s\n", k, v ) )
                                      end
                                      print( "Done." )
                                  end )
                              end
                          end
                          Printout in console:
                          Code:
                          [VScript] {"data":{"MaxHealth": 640,"Health": 640}}                       <-- the JSON data we send
                          [VScript] Script Runtime Error: attempt to call a table value             <-- the asynchronous callback from :Send() that has an error in it
                          stack traceback:
                          The Cherrypy Simple python WebServer Code:
                          Note you "might" need to: "pip install cherrypy simplejson" if you don't have those modules
                          Note: this code is for Python 2.7.x, should work with Python 3.x with minor tweaks
                          Code:
                          import cherrypy
                          import simplejson
                          
                          @cherrypy.expose
                          @cherrypy.tools.json_out()
                          @cherrypy.tools.json_in()
                          class Root:
                          
                              @cherrypy.tools.accept(media='application/json')
                              def GET(self):
                                  print "GET"
                                  return {"operation": "GET", "result": "success"}
                          
                              @cherrypy.tools.accept(media='application/json')
                              def POST(self):
                                  print "POST"
                                  
                                  input_json = cherrypy.request.json
                                  value = input_json["data"]
                                  print value
                                  
                                  return {"operation": "POST", "result": "success"}
                              
                          
                          def web_server():
                              conf = {
                                  'global' : {
                                      'server.socket_host' : '127.0.0.1',
                                      'server.socket_port' : 80,
                                      'server.thread_pool' : 8
                                  },
                                  '/': {
                                      'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
                                      'tools.sessions.on': True,
                                  }
                              }
                              cherrypy.quickstart(Root(), '/', conf)
                          
                          if __name__ == "__main__":
                              print 'starting web server'
                              web_server()
                              print 'done'
                          Printout in the Python Console running the webserver:
                          Code:
                          starting web server
                          [06/Apr/2017:09:41:48] ENGINE Listening for SIGTERM.
                          [06/Apr/2017:09:41:48] ENGINE Bus STARTING
                          [06/Apr/2017:09:41:48] ENGINE Set handler for console events.
                          [06/Apr/2017:09:41:48] ENGINE Started monitor thread 'Autoreloader'.
                          [06/Apr/2017:09:41:48] ENGINE Started monitor thread '_TimeoutMonitor'.
                          [06/Apr/2017:09:41:49] ENGINE Serving on http://127.0.0.1
                          [06/Apr/2017:09:41:49] ENGINE Bus STARTED
                          POST
                          {u'Health': 640, u'MaxHealth': 640}                                                           <--- MY JSON ARRIVED
                          127.0.0.1 - - [06/Apr/2017:09:42:47] "POST / HTTP/1.1" 200 42 "" "Valve/Steam HTTP Client 1.0 (570)"
                          Last edited by nostrademous; 04-06-2017, 06:54 AM.

                          Comment


                          • #14
                            Can confirm. It's borked. The data gets send out, but the callback is treated incorrectly inside the runtime (hence no stacktrace). The behaviour of the same call in the modding API seems to be unaffected though.

                            Comment


                            • #15
                              Originally posted by Lightbringer View Post
                              I I didn't look much into the bot scripting as the lack of the HTTP calls made it uninteresting for me. Guess that change it's what this is all about. Thanks for making me aware of this.
                              What does HTTP have to do with bot scripting?

                              I think the others are mostly doing debugging or stats collection.
                              Explanations on the normal, high and very high brackets in replays: here, here & here
                              Why maphacks won't work in D2: here

                              Comment

                              Working...
                              X