websocket connection does not work - r

I seem to be in struggle with the websockets in R. I wanted to download the streaming data from the BitCoin exchange MtGox directly to R, but R cannot establish the connection.
The websocket specs are defined as:
Host: websocket.mtgox.com or socketio.mtgox.com
Port: 80 or 443 ( ssl )
Namespace: /mtgox (Including beginning slash)
url for more details: https://en.bitcoin.it/wiki/MtGox/API/Streaming
and my code is:
require(websockets)
con = websocket("https://socketio.mtgox.com/mtgox",port=443)
and I always end up with an error:
> con = websocket("https://socketio.mtgox.com/mtgox",port=443)
Error in websocket("https://socketio.mtgox.com/mtgox", port = 443) :
Connection error
Does anyone have an idea what is wrong?
Many thanks.

I've looked at the source code and manual here - https://github.com/rstudio/R-Websockets
The R Websocket library is out of date and not compliant with the WebSocket protocol as it stands.
So you'd need to fix the library or find an alternate one. Fixing the library isn't that hard depending on your ability. I managed to do it here -
https://github.com/zeenogee/R-Websockets
My one is (lazily) hard-coded to MtGox - use at own risk! You'd need to remove the current WebSocket library and install this one. Don't forget Your code is only doing the basic connection. There are a couple more steps to see actual data -
set_callback("receive", function(DATA,WS,HEADER) cat(rawToChar(DATA)), con)
service (con)

Related

Maxscale: maxctrl error when admin_ssl parameters are set in maxscale.cnf

System:
Maxscale 2.5.9
Ubuntu 20.04
In order to access the Web AdminGUI my maxsclale.cnf file looks like this:
[maxscale]
threads=auto
admin_host=0.0.0.0
admin_secure_gui=1
admin_auth=1
admin_enabled=1
admin_gui=1
admin_ssl_key=/etc/ssl/certs/maxscale-key.pem
admin_ssl_cert=/etc/ssl/certs/maxscale-cert.pem
admin_ssl_ca_cert=/etc/ssl/certs/ca-certificates.crt
[...all other configuration..]
With this configuration I can access the Web-AdminGUI on port 8989 from the internal ip address (not 127.0.0.1) by browser.
The SSL key/certs are self-signed .
BUT
When using the command line like:
maxctrl list servers
I get the following error:
Error: Error: socket hang up
When I remove or comment out the lines with the admin_ssl_XXX parameters and restart maxscale, command line works again, but of course the Web-AdminGUI does not.
I tried with various SSL certificate creations (also the one that is listed on the mariadb.com-Website
https://mariadb.com/docs/security/encryption/in-transit/create-self-signed-certificates-keys-openssl/#create-self-signed-certificates-keys-openssl),
the issue remains.
No errors in the maxscale.log whatsoever.
What is the best way to debug this issue?
Or do you have by any chance the right answer at hand?
YOUR help is greatly appreciated!
BR. Martin
You should use maxctrl --secure to encrypt the connections used by it.
Since you are using self-signed certificates, you have to also specify the CA certificate with --tls-ca-cert=/etc/ssl/certs/ca-certificates.crt if it's not installed in the system certificate store.
In addition, you probably need to use --tls-verify-server-cert=false to disable any warnings about self-signed certificates.

Failure to geocode using the ggmap and Google Geocoding API in R; behind company firewall

I am attempting to geocode addresses in R using the geocode() function in the ggmap package. I have done this on my personal computer relatively easily and want to attempt this on my work computer. Generally, I am supposed to register with Google, library the ggmap package, read-in my security key, and then I can use the geocode() function. But I get errors. See below:
# Library package
library(ggmap)
# Set key file
gmAPI <- "key_file.txt"
# Read-in Google API key
gmAPIKey <- readLines(gmAPI)[1]
# Register key
register_google(key = gmAPIKey)
# Geocode Waco, TX
geocode("waco, texas", output = "latlona")
Instead of generating geocoded output, I receive:
Source : https://maps.googleapis.com/maps/api/geocode/json?address=waco,+texas&key=xxx.txt
Error in curl::curl_fetch_memory(url, handle = handle) :
Failed to connect to maps.googleapis.com port 443: Timed out
or sometimes:
Source : https://maps.googleapis.com/maps/api/geocode/json?address=waco,+texas&key=xxx.txt
Error in curl::curl_fetch_memory(url, handle = handle) :
Failed to connect to url port ###: Connection refused
Note: I replaced the actual url/port posted in the error message with url port ### as I imagine this is specific to my computer.
I have a feeling this has to do with my work network. Similar questions have set some configuration using the httr package, but those solutions have not worked for me. It's possible I am entering the wrong information. Any help?
I have had a similar issue at my work, which I managed to solve adding one line of code with a function from the httr library indeed.
I did:
library(httr)
set_config(use_proxy(url="http://proxy.mycompanyname.com", port=****))
Just insert the proxy through which a computer in your company's network connects to the internet and the port that needs to be opened. Commonly used web proxy server ports are 3128, 8080, 6588 and 80.
Hope this helps!
After trying each of the solutions here, and none of them working, I figured out the problem through trial and error. Ultimately, my proxy and port were wrong. In my example, I followed instructions in the link to find my proxy by IE -> Tools -> Internet Options -> Connections tab -> LAN Settings. However, the proxy was somewhat different from what my computer was using. Thus a fool-proof method was to use the curl package and to use the ie_get_proxy_for_url() function to do so programmatically. When I used the output of the ie_get_proxy_for_url() function, #Lennyy's solution worked (and is thus credited). See code:
library(curl)
library(ggmap)
library(httr)
# Get proxy and port
proxyPort <- ie_get_proxy_for_url()
# Split the string to feed the proxy and port arguments
proxyURL <- strsplit(proxyPort, ":")[[1]][1]
portUsed <- as.integer(strsplit(proxyPort, ":")[[1]][2])
# Set configuration
set_config(use_proxy(url=proxyURL, port = portUsed), override = TRUE)
# Geocode Waco, TX
geocode("waco, texas", output = "latlona")
# Output commented below:
# A tibble: 1 x 3
# lon lat address
# <dbl> <dbl> <chr>
# 1 -97.1 31.5 waco, tx, usa

mongo lite server connexion with proxy with R

I am looking to connect to a server using the mongolite package of R but I have the following error
Error: No suitable servers found (serverSelectionTryOnce set): [connection timeout calling ismaster on 'XXX.XX.XX.XXX:XXXX'] where XX are the IP of the server.
Additionaly I have tried to use a proxy to reach out the required server without success.
I have try to create a .Renvion file in my user/Home
and adding the folowing line into this conf file
options(internet.info = 0)
http_proxy=//proxy.serv:0000/ where 0000 are the port of the proxy
Then I am calling the require serveur with its URL in the command line below
mongo(url = "mongodb://XXX.XX.XX.XXX:XXXX", db = "TEST",collection = "TEST1")
without success.
I have allowed the firewall security to the required serveur going forward.
Any Help?

Connection issue R elastic package for Elastic search - one way entry

I have acces to an oneway export function to a public company database through Elastic Search. I have problems connection to it from R and the elastic package.
I have server name(URL), username and password, but I don't have any port number. They describe it as a rest API. Do I have to use the elastic package or is there an easier way around it. The only information I have to the database is: http://distribution.virk.dk/cvr-permanent/virksomhed/_search?.
Host="Distribution.virk.dk"
index="cvr-permanent"
type="virksomhed"
The above link works with HTTR, but I wish to use elastic for automation purposes, when making a large request of data.
so my connect looks like
host = "distribution.virk.dk"
port = ''
path = ''
schema = "http"
user = "user_name"
pass = "secret"
connect(es_host = host,es_user=user, transport=schema, port=port, es_pwd = pass)
Even though I set port to blank it returns 9200.
If I try to use Search
>Search(index="cvr-permanent", type="virksomhed", q='"cvrNummer":"33647093"', size=10)
Error in curl::curl_fetch_memory(url, handle = handle) :
Failed to connect to distribution.virk.dk port 9200: Timed out
(elastic maintainer here)
You should be able to pass in httr::authenticate() to elastic::Search and other functions from the pkg, e.g,.
x <- Search(config = c(httr::verbose(), authenticate("foo", "bar")))
You should see the Authorization: Basic XXXXXX header in the request headers
does that work?

ERROR blpapi_platformtransporttcp.cpp:671 - Connection issue in R

Currently following instructions from rblpapi-intro.Rmd (version date: 2015-08-13) I am wondering why:
library(Rblpapi)
blpConnect()
returns:
17FEB2016_14:27:17.296 7432:8884 ERROR
blpapi_platformtransporttcp.cpp:671 blpapi.session.transporttcp.{3}.
<localhost:8194> Connection failed
17FEB2016_14:27:17.296 7432:8884 WARN blpapi_platformcontroller.cpp:371
blpapi.session.platformcontroller.{3} Platform: 0 failed 1 consecutive
connect attempts, stopped trying to reconnect.
Error: Failed to start session.
given the below default values:
ip: 127.0.0.1
port: 8194
Factually, there is nothing wrong with those values as I've used them in Matlab using con=blp(port,ip2,time) and the connection succeeds perfectly.
EDIT:
The below function has finally worked! a bit weird, as I override the default ip value from blpConnect() by the same value.
blpConnect(host = getOption("blpHost", "127.0.0.1"),
port = getOption("blpPort", 8194L), default = TRUE)
Thus it looks like blpConnect() did'nt pointed to the default ip and port values for some reasons.

Resources