代码之家  ›  专栏  ›  技术社区  ›  Sean Norton

打开地理编码功能连接失败

  •  1
  • Sean Norton  · 技术社区  · 7 年前

    我目前正在运行地理编码功能(使用 google_places 中的函数 googleway 包装)。该函数将运行一段时间(我有近3k个位置),然后抛出以下错误:

    Error in open.connection(con, "rb") : 
      schannel: next InitializeSecurityContext failed: SEC_E_ILLEGAL_MESSAGE (0x80090326) - This error usually occurs when a fatal SSL/TLS alert is received (e.g. handshake failed). More detail may be available in the Windows System event log.
    

    The machine-default permission settings do not grant Local Activation permission for the COM Server application with CLSID 
    {9BA05972-F6A8-11CF-A442-00A0C90A8F39}
     and APPID 
    {9BA05972-F6A8-11CF-A442-00A0C90A8F39}
    

    我真的不知道该如何处理这些信息。据我所知,这似乎是某种安全/防火墙问题。我应该如何授予R运行此函数所需的权限?

    我正在运行Windows 10,Windows Defender作为防病毒/防火墙。作为参考,这是我用于地理编码的函数:

    metro.locater <- function(lat, lon){
    
      library(googleway)
    
      #putting latitude and longitude into the same vector
      latlon <- c(lat, lon)
    
      #getting places result
      res <- google_places(location = latlon, 
                           place_type = "subway_station", radius = 50000,
                           rankby="distance",
                           key = "myKey")
      #condition handling
      if(res$status == 'OK'){
      closest <- res$results[1:3, ]
    
      return(closest)} else {
      try(return(res$status))
      }
    
    }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Sean Norton    7 年前

    我可以通过使用一个副词来解决这个问题,这个副词曾与另一个地理编码函数一起使用,该函数在无法提供结果时尝试运行该函数5次。考虑到这一点,这似乎只是一个暂时的错误,而不是一个系统性的问题。

    我用的副词是:

    safely <- function(fn, ..., max_attempts = 5) {
      function(...) {
        this_env <- environment()
        for(i in seq_len(max_attempts)) {
          ok <- tryCatch({
              assign("result", fn(...), envir = this_env)
              TRUE
            },
            error = function(e) {
              FALSE
            }
          )
          if(ok) {
            return(this_env$result)
          }
        }
        msg <- sprintf(
          "%s failed after %d tries; returning NULL.",
          deparse(match.call()),
          max_attempts
        )
        warning(msg)
        NULL
      }
    }
    

    摘自 Repeating values in loop until error disappears .