phillc73 / abettor

An R package for connecting to the online betting exchange Betfair, via their API-NG product, using JSON-RPC.
Other
51 stars 36 forks source link

Login failure #21

Closed bcaneco closed 5 years ago

bcaneco commented 5 years ago

Hi,

Yesterday I started getting this error at login:

> loginBF(username = user, password = pass, applicationKey = appKey)
<SSL_CONNECT_ERROR in function (type, msg, asError = TRUE) {    if (!is.character(type)) {        i = match(type, CURLcodeValues)  typeName = if (is.na(i))   character()  else names(CURLcodeValues)[i]    }    typeName = gsub("^CURLE_", "", typeName)    fun = (if (asError)    stop  else warning)    fun(structure(list(message = msg, call = sys.call()), class = c(typeName,   "GenericCurlError", "error", "condition")))}(35L, "error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol",     TRUE): error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol>
Error in function (type, msg, asError = TRUE)  : 
  error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

Is this related with Betfair's recent change in communications security settings, allowing only TLS 1.2 protocols?

This is the email I got from Betfair, on 01/02/2019.

Subject: Betfair API - TLS 1.2 - from 7th February 2019 (...) Please be aware that from 7th February, the only protocol for securing the communication between Betfair servers and web browsers at login will be TLS 1.2. Older versions (TLS.1.0, TLS.1.1 or SSLv3) will no longer work. Although we don't expect this to have an impact on API clients we'd recommend that you refer to the following resources depending on your programming language/framework to confirm that your using TLS 1.2 or above: (...)

My current version of RCurl appears to be using an older protocol

> RCurl::curlVersion()$ssl_version
[1] "OpenSSL/1.0.0o"

Is there a quick fix to this?

Thank you!

JJHeathview commented 5 years ago

Hi Phil, I trust you are well.

had the same problem, and the same error message.

I found this on Stackoverflow regarding TLS protocols and RCurl(), it may be of use : https://stackoverflow.com/questions/38130293/tls-v1-1-tls-v1-2-support-in-rcurl

Best Wishes, Jason Hathorn


From: Bruno Caneco notifications@github.com Sent: 20 February 2019 09:06 To: phillc73/abettor Cc: Subscribed Subject: [phillc73/abettor] Login failure (#21)

Hi,

Yesterday I started getting this error at login:

loginBF(username = user, password = pass, applicationKey = appKey) <SSL_CONNECTERROR in function (type, msg, asError = TRUE) { if (!is.character(type)) { i = match(type, CURLcodeValues) typeName = if (is.na(i)) character() else names(CURLcodeValues)[i] } typeName = gsub("^CURLE", "", typeName) fun = (if (asError) stop else warning) fun(structure(list(message = msg, call = sys.call()), class = c(typeName, "GenericCurlError", "error", "condition")))}(35L, "error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol", TRUE): error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol> Error in function (type, msg, asError = TRUE) : error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

Is this related with Betfair's recent change in communications security settings, allowing only TLS 1.2 protocols?

This is the email I got from Betfair, on 01/02/2019.

Subject: Betfair API - TLS 1.2 - from 7th February 2019 (...) Please be aware that from 7th February, the only protocol for securing the communication between Betfair servers and web browsers at login will be TLS 1.2. Older versions (TLS.1.0, TLS.1.1 or SSLv3) will no longer work. Although we don't expect this to have an impact on API clients we'd recommend that you refer to the following resources depending on your programming language/framework to confirm that your using TLS 1.2 or above: (...)

My current version of RCurl appears to be using an older protocol

RCurl::curlVersion()$ssl_version [1] "OpenSSL/1.0.0o"

Is there a quick fix to this?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fphillc73%2Fabettor%2Fissues%2F21&data=02%7C01%7C%7C5162a875dc74442b9d3808d69712a7d3%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636862503707326734&sdata=pyl%2BFGOIuOrJqxTySR8Yk7u23HGJRR56f3bbn13XOSU%3D&reserved=0, or mute the threadhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAJyur_uBcYSkLQl48Hggqg6csJfDp-feks5vPRAAgaJpZM4bEu4K&data=02%7C01%7C%7C5162a875dc74442b9d3808d69712a7d3%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636862503707346757&sdata=TzZgoXXmj0Yv3YW0mGTdJYYFtfPV5LEcH3QeGliW42I%3D&reserved=0.

willtudorevans commented 5 years ago

Also having the same problem on Windows, Mac OS seems to work fine still.

willtudorevans commented 5 years ago

I built this function as a replacement for loginBF which I think solves the issue.

logBF <- function(username, password, applicationKey, sslVerify = T) {
  credentials <- paste0("username=", username, "&password=", password)
  loginReturn <- httr::POST(url = "https://identitysso.betfair.com/api/login", config = httr::config(ssl_verifypeer = T),
                            query = credentials, 
                            httr::add_headers(Accept = "application/json", `X-Application` = applicationKey))
  authenticationKey <- httr::content(loginReturn)
  Sys.setenv(product = authenticationKey$product)
  Sys.setenv(token = authenticationKey$token)
  return(paste0(authenticationKey$status, ":", authenticationKey$error))
}
statsgeeknz commented 5 years ago

@willtudorevans - legend. Thanks

phillc73 commented 5 years ago

Thanks everyone for reporting this issue. It's a pleasant surprise to see this package still has some love!

Especially thanks to @willtudorevans for the replacement function. If @JJHeathview and @bcaneco can confirm this resolves the problem, I will update the function within the package.

bcaneco commented 5 years ago

Yes, @willtudorevans absolutely smashed this issue into pieces! Thank you!

The KeepAlive() function also requires updating. The following replacement function seems to do the trick.

kpAlive <- function (suppress = TRUE, sslVerify = TRUE) 
{
  product <- Sys.getenv("product")
  token <- Sys.getenv("token")

  if (suppress){
    keepAlive <- suppressWarnings(httr::content(
          httr::POST(url = "https://identitysso.betfair.com/api/keepAlive", config = httr::config(ssl_verifypeer = sslVerify),
                     httr::add_headers(Accept = "application/json", `X-Application` = product, 
                                       `X-Authentication` = token, `Content-Type` = "application/json"))
      )
    )
  }else{
    keepAlive <- httr::content(
        httr::POST(url = "https://identitysso.betfair.com/api/keepAlive", config = httr::config(ssl_verifypeer = sslVerify),
                   httr::add_headers(Accept = "application/json", `X-Application` = product, 
                                     `X-Authentication` = token, `Content-Type` = "application/json")
      )
    )
  }

  return(paste0(keepAlive$status, ":", keepAlive$error))
}

Thanks for keeping this very useful package going Phil.

Cheers

phillc73 commented 5 years ago

Thanks @bcaneco, I'll update that function too.

To be honest, I haven't done anything to keep the package going in some time. I appreciate everyone's feedback and enhancement suggestions. They actually provide me some motivation to spend time working on this.

JJHeathview commented 5 years ago

Hi, Yes, the new function works for me, SUCCESS: returned.

Many thanks, much appreciated , it's a cool package, great you still maintain it. Regards, Jason Hathorn


From: Phill notifications@github.com Sent: 20 February 2019 12:07 To: phillc73/abettor Cc: Jason Hathorn; Mention Subject: Re: [phillc73/abettor] Login failure (#21)

Thanks @bcanecohttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fbcaneco&data=02%7C01%7C%7C13b54483837e45b8a39308d6972c0405%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636862612626569554&sdata=LEgMVKjgN96OI2Q0znVtBZu4u17OE1IecdpQ%2FBOR9V4%3D&reserved=0, I'll update that function too.

To be honest, I haven't done anything to keep the package going in some time. I appreciate everyone's feedback and enhancement suggestions. They actually provide me some motivation to spend time working on this.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fphillc73%2Fabettor%2Fissues%2F21%23issuecomment-465547903&data=02%7C01%7C%7C13b54483837e45b8a39308d6972c0405%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636862612626579571&sdata=FZCcvSVIXUhws26xY77QLqwggPs8F631wN8FmPUREeE%3D&reserved=0, or mute the threadhttps://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAJyur6oMx7N_Sf8fTBdBHggqJgFEByCnks5vPTqMgaJpZM4bEu4K&data=02%7C01%7C%7C13b54483837e45b8a39308d6972c0405%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C636862612626589582&sdata=ZRQrnJBdmRDlE9d5juZqQf2Bx%2FqeuDFTMtdwSfhQ7lE%3D&reserved=0.

CronoxBC commented 5 years ago

The function above isn't working for me on my Windows VPS, it just hangs and if I stop the process it returns: Error in curl::curl_fetch_memory(url, handle = handle) : Operation was aborted by an application callback

Any ideas??

thewetdog commented 5 years ago

Hi, I was wondering if this has to deal with logging issues / time out. I am running the following:

eventID <- 29212093 #could be any id
MarketCatalogue <- listMarketCatalogue(
    eventTypeIds = 1,
    eventIds = eventID,
    marketTypeCodes = "MATCH_ODDS"
)

So far so good. The following gives me issues at times:

listMarketBook(marketIds = MarketCatalogue$marketId[1], priceData = "EX_ALL_OFFERS")

I run listMarketBook as above and it returns data as expected. I re-run it after a few seconds and it returns an empty data frame. Running it again after a while and data is there again. Any pointers to why this is happening?

Additionally, I sometimes run into this error:

Error in function (type, msg, asError = TRUE)  : 
  Failed to connect to api.betfair.com port 443: Timed out

I am using "logBF" function as provided by @willtudorevans. I have read that this error is related to proxy authentication but I have no clue how to go about it.

Thanks for any pointers.

phillc73 commented 5 years ago

@thewetdog As noted by @bcaneco the keepAlive() function also requires updating. Perhaps this will solve your issue.

I am planning on updating the package this week (truly I hope so) with these enhanced functions.

phillc73 commented 5 years ago

Please test the updated loginBF() and keepAlive() functions. I'll close this Issue now, but happen to re-open if problem persists.