You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在R中构建Exmo API认证请求时nonce格式错误(40007)求助

Fixing "Incorrect format parameter 'nonce'" Error for Exmo API in R

Let's break down why you're hitting that 40007: Incorrect format parameter 'nonce' error and fix it step by step.

First, let's go over the key mistakes in your original code:

  • Nonce is in the wrong place: Exmo expects nonce to be part of the request body (form data), not a request header.
  • Sign header is hardcoded: You set Sign = "secret key" instead of using the generated HMAC signature.
  • Signature in query params: You added the signature to the query argument, but Exmo doesn't expect it there—authentication uses the Sign header instead.
  • Nonce type issue: Using as.numeric(as.POSIXct(Sys.time())) gives a timestamp with decimals, but Exmo requires an integer value for nonce.

Here's the corrected code that should work:

# Load required packages (make sure they're installed first)
library(httr)
library(digest)
library(jsonlite)

# Your API credentials (replace with your actual keys)
public_key <- "your_public_key_here"
secret_key <- "your_secret_key_here"

# Generate integer nonce (Exmo requires integer timestamp)
nonce <- as.integer(Sys.time())

# Create the request body parameters (nonce is mandatory for authenticated requests)
body_params <- list(nonce = nonce)

# Generate HMAC-SHA512 signature
# The string to sign is the URL-encoded form of the body parameters
string_to_sign <- paste(names(body_params), body_params, sep = "=", collapse = "&")
signature <- hmac(key = secret_key, object = string_to_sign, algo = "sha512")

# Send POST request to Exmo's user_info endpoint
acc <- POST(
  url = "https://api.exmo.com/v1/user_info/",
  add_headers(
    Key = public_key,
    Sign = signature
  ),
  body = body_params,
  encode = "form"  # This ensures the body is sent as x-www-form-urlencoded
)

# Parse the response
get_exmo <- content(acc, as = "text")
get_exmo_json <- fromJSON(get_exmo)

# Check the result
print(get_exmo_json)

Let's verify the critical fixes:

  1. Nonce as integer: as.integer(Sys.time()) gives a whole number timestamp, which matches Exmo's requirement.
  2. Nonce in request body: We pass nonce via the body argument with encode = "form", which is how Exmo expects authenticated parameters.
  3. Correct Sign header: The generated signature is used here instead of a hardcoded string.
  4. No extra query params: We don't pass signature in the URL query—authentication is handled via headers and body.

If you still run into issues, double-check that your public/secret keys are correct, and ensure the nonce value is always increasing (each subsequent request needs a higher nonce than the last).

内容的提问来源于stack exchange,提问作者Jaap

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 09:24:49