none
One-box configuration runs but cannot connect from other machine RRS feed

  • Question

  • Hi All,

    I encountered some issue with MRS:

    I successfully installed MS R Server on Win Server 2012 R2, configured as one-box. I’m able to connect to localhost:12800 using RStudio:

    library(mrsdeploy)
    
    remoteLogin('http://localhost:12800',session = T, username=
    'admin', password='somepass')

    I can also publish a service like:

    addOne <- function(x) x +1
    
    api <- publishService('addone', code=addOne, inputs =
    list(x='numeric'),outputs=list(answer='numeric'),v='v1.0.1')
    
    
    
    print(api$capabilities())## prints good

    However, if I browse in web-browser, the swagger.json page doesn’t show up, nor does this work:

    library(httr)
    
    GET(url = "http://localhost:12800/api/addone/v1.0.1/swagger.json")
    
    # response status code is 401, not authorized!

    Plus, I’m not able to connect to this endpoint from another machine, which installs R Client successfully:

    library(mrsdeploy)
    
    remoteLogin('http://MyHost:12800',session = T, username=
    'admin', password='somepass')
    
    # will give 504 Gateway timeout error!

    I don't think it’s my firewall that stops me because

    1.       I specifically opened 12800 TCP
    2.       Other web application can open ports successfully without tuning the firewall at all

    So, I’m wondering if I have understood the framework properly:


    For a One-Box configuration, I thought I’m still able to connect to R Server from a different machine and end-users should be able to consume REST API. However I’m not able to do so and the swagger.json doesn’t even show on localhost because of authentication failed.

    Would you please point me to the right direction?

    Any help would be highly appreciated. Thanks!

    Ricky

    Wednesday, March 8, 2017 8:10 PM

Answers

  • Hello,

    I believe you are missing the bearer token. You must request the file as an authenticated user with an active bearer token in the request header (since all API calls must be authenticated). Learn more: https://msdn.microsoft.com/en-us/microsoft-r/operationalize/app-developer-get-started#authentication

    It might be easier to get it in R instead. Learn more here: https://msdn.microsoft.com/en-us/microsoft-r/operationalize/data-scientist-manage-services#consume-web-services

    • Marked as answer by RickyHuangAB Thursday, March 9, 2017 12:01 AM
    Wednesday, March 8, 2017 8:30 PM
    Moderator

All replies

  • Hello,

    I believe you are missing the bearer token. You must request the file as an authenticated user with an active bearer token in the request header (since all API calls must be authenticated). Learn more: https://msdn.microsoft.com/en-us/microsoft-r/operationalize/app-developer-get-started#authentication

    It might be easier to get it in R instead. Learn more here: https://msdn.microsoft.com/en-us/microsoft-r/operationalize/data-scientist-manage-services#consume-web-services

    • Marked as answer by RickyHuangAB Thursday, March 9, 2017 12:01 AM
    Wednesday, March 8, 2017 8:30 PM
    Moderator
  • Thank you Josée for quick reply!

    ******** Solved by fixing another issue, see below, i think it might be useful for others! **********

    I am able to authenticate on local host:

    library(httr)
    library(curl)
    
    r <- POST("http://localhost:12800/login", 
         body=list(username='admin',password='somepass')
         , encode='json')
    at <- jsonlite::fromJSON( content(r, as = 'text') )$access_token
    cat(at)
    
    
    ## now we have the auth token
    
    
    url="http://localhost:12800/api/addone/v1.0.1/swagger.json"
    
    port=12800
    proxy="http://proxyaddress"# you may not need them!
    proxyport=8080
    noproxy='localhost'
    
    
    
    h <- new_handle()
    handle_setheaders(h,.list=list(Authorization=paste0("Bearer ",at,"")))
    handle_setopt(h, .list = list(customrequest = "GET",port=port,proxy=proxy,proxyport=proxyport,noproxy=noproxy))
    
    r1 <- curl_fetch_memory(url, h)
    
    r1$status_code
    
    jsonlite::fromJSON(rawToChar(r1$content))
    


    I wasn't able POST nor can i remoteLogin into my server from another machine.


    "Kestrel": {
        "Port": "12800",
        "Host": "0.0.0.0",
        "HttpsEnabled": false,
        "HttpsCertificate": {
          "Enabled": false,
          "Description": "Enable this section if you want to enable SSL on Kestrel",
          "StoreName": "My",
          "StoreLocation": "LocalMachine",
          "SubjectName": ""
        }

    it will generate error code 504.

    ***Solved*** This is because, my company has a proxy for all internet traffics. by default, httr package will use the Proxy while it really shouldn't (because our server sits in intranet). The workaround is to pass config proxy='', like this:

    library(httr)
    r <- POST("http://MyHost:12800/login",
               body=list(username='admin',password='somepass')
               , encode='json',config = httr::config("proxy"=''))
    r$status_code
    # status is 200!

    Hopefully this can help some guys who sit behind a proxy, which is pretty common in company world.

    Thanks! Finally it works! 

    Ricky

    Thursday, March 9, 2017 12:01 AM