R httr GET请求400错误GDAX

编程入门 行业动态 更新时间:2024-10-09 11:28:03
本文介绍了R httr GET请求400错误GDAX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正尝试使用 R 命中 GDAX ,并获得以下问题。如何使用 httr 解决问题。

响应[https ://api-public.sandbox.gdax/accounts] 日期:2017-12-07 20:30 状态:400 Content-Type:application / json; charset = utf-8 大小:53 B

以下是我的代码。请注意,这个问题只存在于 httr 包而不是 RCurl (代码见附录)

$ b $

library(digest) library(httr) library(RCurl)#for base64Decode url< - api-public.sandbox.gdax/accounts秘密&#;#来自GDAX沙箱的API秘密 api.key< - #API密钥来自GDAX沙箱密码短语< - #来自GDAX沙箱的API密码短语 时间戳< - 格式(as.numeric(Sys.time()),digits = 13)#创建nonce key< - base64Decode(secret,mode =raw)#encode api secret what < - paste0(timestamp,GET,req.url) sign< - base64Encode( hmac(key,what,algo =sha256,raw = TRUE)) 连接器< - list(url = url,nonce = timestamp,signature = sign)) GET(url = connector $ url, add_headers('CB-ACCESS-KEY'= api.key,'CB-ACCESS-SIGN'=连接器$签名,'CB-ACCESS-TIMESTAMP'=连接器$ nonce, 'CB-ACCESS-PASSPHRASE'=密码,'Content-Type'='application / json'))

但是,如果我使用 RCurl ,那么我可以使用以下代码获得响应内容。

解决方案

除非沙箱被恢复(我没有资料可以这样说),但是它在2017年年初退役,通讯方式很少,而且据我所知,仍然是这个日期。我将它记录在 gdax-java 库中。

I am trying to hit GDAX using R and getting the following issue. How do I solve for the issue using httr.

Response [api-public.sandbox.gdax/accounts] Date: 2017-12-07 20:30 Status: 400 Content-Type: application/json; charset=utf-8 Size: 53 B

Below is my code. Please note that the issue exists only with httr package and not with RCurl (code provided in appendix)

library(digest) library(httr) library(RCurl) # for base64Decode url <- "api-public.sandbox.gdax/accounts" secret <- # API secret from GDAX sandbox api.key <- # API key from GDAX sandbox passphrase <- # API passphrase from GDAX sandbox timestamp <- format(as.numeric(Sys.time()), digits=13) # create nonce key <- base64Decode(secret, mode="raw") # encode api secret what <- paste0(timestamp, "GET", req.url) sign <- base64Encode(hmac(key, what, algo="sha256", raw=TRUE)) connector <- list(url = url, nonce = timestamp, signature = sign)) GET(url=connector$url, add_headers( 'CB-ACCESS-KEY'=api.key, 'CB-ACCESS-SIGN'=connector$signature, 'CB-ACCESS-TIMESTAMP'=connector$nonce, 'CB-ACCESS-PASSPHRASE'=passphrase, 'Content-Type'='application/json' ) )

If however, I use RCurl then I am able to get a response content using the following code.

httpheader <- list('CB-ACCESS-KEY'=api.key, 'CB-ACCESS-SIGN'=sign, 'CB-ACCESS-TIMESTAMP'=timestamp, 'CB-ACCESS-PASSPHRASE'=passphrase, 'Content-Type'='application/json') connector <- list(url = url, header = httpheader) getURLContent(url = connector$url, curl=getCurlHandle(useragent="R"), httpheader=connector$header)

解决方案

unless the sandbox was reinstated (I have no info to say it was) it was decommissioned early 2017 with very little in the way of communication and is still down to this date as far as I'm aware. I documented this on the gdax-java lib.

更多推荐

R httr GET请求400错误GDAX

本文发布于:2023-10-12 05:14:38,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   httr   GDAX

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!