gpt4 book ai didi

google-apps-script - 仅通过菜单运行 Google 表格脚本时来自 API 的 "Request Blocked"(在脚本编辑器中运行)

转载 作者:行者123 更新时间:2023-12-05 07:28:10 24 4
gpt4 key购买 nike

我有一个通过脚本编辑器可以正常工作的 Google 表格脚本。当我尝试通过菜单选项运行它时,它会从 API 中显示“请求被阻止”。该脚本基本上是在尝试攻击 Binance API。

代码如下:

function getMyTrades() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var thresholdVal = parseFloat(ss.getSheetByName("Settinngs").getRange("C1").getValue());
var balancesSheet = ss.getSheetByName("Account Overview");
var openOrdersSheet = ss.getSheetByName("OpenOrders");

var api = "/api/v3/account";
var json = getBinanceResponse(api,"");
var balancesArr = json['balances'];
// remaining code here.....
}


function getBinanceResponse(api,string){
var key = 'key_here';
var secret = 'secret_key here';
var timestamp = Number(new Date().getTime()).toFixed(0);
string += "timestamp=" + timestamp;
var baseUrl = "https://api.binance.com";
var signature = Utilities.computeHmacSha256Signature(string, secret);

signature = signature.map(function(e) {
var v = (e < 0 ? e + 256 : e).toString(16);
return v.length == 1 ? "0" + v : v;
}).join("");

var query = "?" + string + "&signature=" + signature;

var params = {
'method': 'get',
'headers': {'X-MBX-APIKEY': key},
'muteHttpExceptions': true,
};

var data = UrlFetchApp.fetch(baseUrl + api + query, params);
Logger.log(data)

return JSON.parse(data);
}

这是请求被阻止时币安的响应

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE>ERROR: The request could not be satisfied</TITLE>
</HEAD><BODY>
<H1>403 ERROR</H1>
<H2>The request could not be satisfied.</H2>
<HR noshade size="1px">
Request blocked.

<BR clear="all">
<HR noshade size="1px">
<PRE>
Generated by cloudfront (CloudFront)
Request ID: Ov-DKv4UDH88eYZbo366xy7BsdsJVVcvHxLLPLeS2li6VqXw1qp05K4fw==
</PRE>
<ADDRESS>
</ADDRESS>
</BODY></HTML>

最佳答案

我在 Reddit 上找到了解释: https://www.reddit.com/r/GoogleAppsScript/comments/p3zuox/binance_data/ https://www.binance.com/en/support/faq/360004492232

Binance HTTP 403 return code is used when the WAF Limit (Web Application Firewall) has been violated.

这对我有用

    var baseUrl = "https://api.binance.com";
baseUrl.replace(/api/, `api${Math.floor(Math.random() * 4) || ''}`);

来自 Binance API Documentation

The base endpoint is: https://api.binance.com If there are performance issues with the endpoint above, these API clusters are also available: https://api1.binance.com https://api2.binance.com https://api3.binance.com

关于google-apps-script - 仅通过菜单运行 Google 表格脚本时来自 API 的 "Request Blocked"(在脚本编辑器中运行),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53568508/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com