How to fix Invalid API-key, IP, or permissions for action error?
Solution 1
I believe this was the error I was running across in python. If you set up your binance account with binance.us instead of binance.com you need to make sure that you change it in the scource files. In python it was as easy as passing the 'tld="us"' parameter when initializing the client class.
I saw that you had " url = |https://api.binance.com/api/v1/userDataStream|" You may need " url = |https://api.binance.us/api/v1/userDataStream|"
Also, I noticed that your url had api/v1, just wanted to make sure that when you are grabbing account information or other requests that require your api_secret key it should roll over api/v2 or api/v3.
I am not familiar with C++ but here is a solution to perform a find/replace in python. Hope this information helps you!
You will need to navigate to the directory your github-downloaded files are located and try the following:
check this code to make sure it is not replacing any .com's you may need.
import os
for root, dirs, files in os.walk(os.curdir):
for f in files:
file_name = os.path.join(root, f):
try:
with open(file_name, 'r') as fp:
data = fp.read().replace('.com', '.us')
with open(file_name, 'w') as fp:
fp.write(data)
except:
print(f.ljust(20), 'failed')
Solution 2
For me, I had to log into the Binance API Management page and update my whitelisted IP addresses as I had since changed my Internet provider. Always worth checking!
Related videos on Youtube
Mustafa Güngör
Updated on June 04, 2022Comments
-
Mustafa Güngör almost 2 years
This is Binance cryptoexchange api. Im trying to get account informations but I could not do that. It's official C++ Api. This is github link. This is error on terminal. When you answering the question, Please be easy. I am newbie
2020-01-22 10:32:04 085219 :
2020-01-22 10:32:04 085245 : url = |https://api.binance.com/api/v1/userDataStream|
2020-01-22 10:32:04 085253 :
2020-01-22 10:32:04 698466 :
2020-01-22 10:32:04 698529 : done
2020-01-22 10:32:04 701234 : done
2020-01-22 10:32:04 701434 : Done.
2020-01-22 10:32:04 701472 : Done.
{ "code" : -2015, "msg" : "Invalid API-key, IP, or permissions for action." }
[2020/01/22 10:32:04:7018] NOTICE: libuv support not compiled in
[2020/01/22 10:32:04:7045] NOTICE: Creating Vhost 'default' port -1, 1 protocols, IPv6 off
[2020/01/22 10:32:04:7046] NOTICE: created client ssl context for default
[2020/01/22 10:32:04:7099] NOTICE: lws_client_connect_2: 0x239f3e0: address stream.binance.com
[2020/01/22 10:32:05:3128] NOTICE: lws_client_connect_2: 0x239f3e0: address stream.binance.com
Here i entered my keys.
using namespace std; #define API_KEY "my api key here,deleted for security" #define SECRET_KEY "secret key is here, deleted for security"
and main function
int main() { Json::Value result; long recvWindow = 10000; string api_key = API_KEY; string secret_key = SECRET_KEY; BinaCPP::init( api_key , secret_key ); // User Balance BinaCPP::get_account( recvWindow , result ); for ( int i = 0 ; i < result["balances"].size() ; i++ ) { string symbol = result["balances"][i]["asset"].asString(); userBalance[symbol]["f"] = atof( result["balances"][i]["free"].asString().c_str() ); userBalance[symbol]["l"] = atof( result["balances"][i]["locked"].asString().c_str() ); } print_userBalance(); // User data stream BinaCPP::start_userDataStream(result ); cout << result << endl; string ws_path = string("/ws/"); ws_path.append( result["listenKey"].asString() ); BinaCPP_websocket::init(); BinaCPP_websocket::connect_endpoint( ws_userStream_OnData , ws_path.c_str() ); BinaCPP_websocket::enter_event_loop(); }
and this is a part of BinaCPP.cpp
#include "binacpp.h" #include "binacpp_logger.h" #include "binacpp_utils.h" string BinaCPP::api_key = "my api key here"; string BinaCPP::secret_key = "secret key here"; CURL* BinaCPP::curl = NULL; //--------------------------------- void BinaCPP::init( string &api_key, string &secret_key ) { curl_global_init(CURL_GLOBAL_DEFAULT); BinaCPP::curl = curl_easy_init(); BinaCPP::api_key = api_key; BinaCPP::secret_key = secret_key; }
-
Botje over 4 yearsDid you fill in
BinaCPP::api_key
withAPI_KEY
as well? It is hard to tell. -
Mustafa Güngör over 4 years@Botje Yes sir, I did.
-
Botje over 4 yearsCan you do the same action with, say,
curl
from the same IP? That rules out that your API key is invalid for the linked action/IP combination. -
Mustafa Güngör over 4 years@Botje I guess found the reason but I am using official API and example. I understand nothing. pastebin.pl/view/f4e0e9cf
-
Botje over 4 yearsHow can you simultaneously fail to compile the example and yet have it produce erorr messages?
-
-
asparism over 3 yearstld='us' worked for me. there are several places where american users have to double check to make sure they are connecting at the right points, like the url and which app they download.