Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Error: Request failed with status: 451 #142

Open
RobertSmith8 opened this issue Nov 30, 2022 · 39 comments
Open

[BUG] Error: Request failed with status: 451 #142

RobertSmith8 opened this issue Nov 30, 2022 · 39 comments
Assignees
Labels
bug Something isn't working

Comments

@RobertSmith8
Copy link

RobertSmith8 commented Nov 30, 2022

Describe the bug
Script has been working flawless over a year but today I started to get error 451: Unavailable For Legal Reasons

Binance API last call
Wed Nov 30 2022 09:10:50 GMT+0100 (Central European Standard Time)

I'm from Europe, I guess this error is due to that Google runs on server in a “Restricted Location” or?

attempting to access the Binance Platform or the Binance Services from, or otherwise acting on behalf of a person or legal entity that is resident or located in, a Restricted Location. For the purposes hereof, “Restricted Location” shall include the United States, Malaysia, Ontario (Canada), and such other locations as designated by Binance Operators from time to time as a “Restricted Location”
https://www.binance.com/en/terms

I'm able to call API Locally but unable to do it using Google script, simple test is to use this API call in a browser.
https://api.binance.com/api/v3/time

Update:
https://data.binance.com/ can be used for getting market data.

replace:
const SPOT_API_URL = "https://api.binance.com";
with
const SPOT_API_URL = "https://data.binance.com";

and add data.binance.com to urlFetchWhitelist

Work around (not needed any more)

I might have found a work around to get some prices but obvious not balance, open orders etc. since I don't have a US account.

replace:
const SPOT_API_URL = "https://api.binance.com";
with
const SPOT_API_URL = "https://api.binance.us";

and add .us to urlFetchWhitelist

  "urlFetchWhitelist": [
    "https://api.binance.com/",
    "https://api.binance.us/",
    "https://api1.binance.com/",
    "https://api1.binance.us/",
    "https://api2.binance.com/",
    "https://api2.binance.us/",
    "https://api3.binance.com/",
    "https://api3.binance.us/",
    "https://fapi.binance.com/",
    "https://dapi.binance.com/",
  ]

Edit:
Same problem with DEMO
https://docs.google.com/spreadsheets/d/1AcOcPFsncrDB_ve3wWMHwfiFql6A4hmG1sFc01LLTDg

@RobertSmith8 RobertSmith8 added the bug Something isn't working label Nov 30, 2022
@RobertSmith8 RobertSmith8 changed the title [BUG] Error: Request failed with status: 403 [BUG] Error: Request failed with status: 451 Nov 30, 2022
@pedro-cf
Copy link

Also experiencing this error
"Error: Request failed with status: 451 (linha 2751)."
451: Unavailable For Legal Reasons

@clpacheco90
Copy link

Same here. But I'm from Brazil.

@pedro-cf
Copy link

pedro-cf commented Nov 30, 2022

Not sure if related to this:
image

Exception: Request failed for https://api.binance.com returned code 451. Truncated server response: { "code": 0, "msg": "Service unavailable from a restricted location according to 'b. Eligibility' in https://www.binance.com/en/terms. Please c... (use muteHttpExceptions option to examine full response) (linha 131).

@RobertSmith8
Copy link
Author

RobertSmith8 commented Nov 30, 2022

Current urlFetchWhitelist

  "urlFetchWhitelist": [
    "https://api.binance.com/",
    "https://api1.binance.com/",
    "https://api2.binance.com/",
    "https://api3.binance.com/",
    "https://fapi.binance.com/",
    "https://dapi.binance.com/"
 ]

@cristipurdel
Copy link

cristipurdel commented Nov 30, 2022

Current urlFetchWhitelist

  "urlFetchWhitelist": [
    "https://api.binance.com/",
    "https://api1.binance.com/",
    "https://api2.binance.com/",
    "https://api3.binance.com/",
    "https://fapi.binance.com/",
    "https://dapi.binance.com/"
 ]

same issue from germany
also the following links are not working
https://api3.binance.com/api/v3/ticker/price
at least the staking link is still working
https://www.binance.com/gateway-api/v1/friendly/pos/union?status=ALL&pageSize=200

looks like issue on api dev side, better upvote :)
https://dev.binance.vision/t/service-unavailable-from-a-restricted-location/13813

@rasatus1
Copy link

rasatus1 commented Dec 1, 2022

Same here, I'm from Romania

@akshayj12489
Copy link

I'm from India and facing similar issue, hope the developer will look into it.

@tfishnz
Copy link

tfishnz commented Dec 1, 2022

Not just me then! (yay). Same issue - New Zealand based
Thanks for all your hard work @diegomanuel i've been using your code for well over a year to track things. Hopefully there is a way to resolve this.

@diogopms
Copy link

diogopms commented Dec 1, 2022

Same issue here in Portugal

@ShoaibZahoor
Copy link

ShoaibZahoor commented Dec 1, 2022 via email

@swiftfloe
Copy link

Same issue here in UAE. This script has been working perfectly for the last 12 months, but it's now just throwing our a 451 status error.

Concerningly, this appears to be a legal status code exception, suggesting the API calls are now region restricted? I note the developer is based in Argentina, so I'm wondering if the API requests are now region-locked to Argentina only? Has anyone tried running this on a VPN with Argentina as the host country?

@yastrebua2
Copy link

The location of the user has nothing to do with it. Requests are sent by google server

@RobertSmith8
Copy link
Author

RobertSmith8 commented Dec 2, 2022

I might have found a work around to get some prices but obvious not balance, open orders etc. since I don't have a US account.

replace:
const SPOT_API_URL = "https://api.binance.com";

with
const SPOT_API_URL = "https://api.binance.us";

and add .us to urlFetchWhitelist

  "urlFetchWhitelist": [
    "https://api.binance.com/",
    "https://api.binance.us/",
    "https://api1.binance.com/",
    "https://api1.binance.us/",
    "https://api2.binance.com/",
    "https://api2.binance.us/",
    "https://api3.binance.com/",
    "https://api3.binance.us/",
    "https://fapi.binance.com/",
    "https://dapi.binance.com/",
  ]

@akshayj12489
Copy link

I might have found a work around to get some prices but obvious not balance, open orders etc. since I don't have a US account.

replace: const SPOT_API_URL = "https://api.binance.com";

with const SPOT_API_URL = "https://api.binance.us";

and add .us to urlFetchWhitelist

  "urlFetchWhitelist": [
    "https://api.binance.com/",
    "https://api.binance.us/",
    "https://api1.binance.com/",
    "https://api1.binance.us/",
    "https://api2.binance.com/",
    "https://api2.binance.us/",
    "https://api3.binance.com/",
    "https://api3.binance.us/",
    "https://fapi.binance.com/",
    "https://dapi.binance.com/",
  ]

Binance US have very limited no of coins also liquidity is not good so if you are using historical data you might get very poor results.

@cristipurdel
Copy link

cristipurdel commented Dec 3, 2022

I might have found a work around to get some prices but obvious not balance, open orders etc. since I don't have a US account.

replace: const SPOT_API_URL = "https://api.binance.com";

with const SPOT_API_URL = "https://api.binance.us";

and add .us to urlFetchWhitelist

  "urlFetchWhitelist": [
    "https://api.binance.com/",
    "https://api.binance.us/",
    "https://api1.binance.com/",
    "https://api1.binance.us/",
    "https://api2.binance.com/",
    "https://api2.binance.us/",
    "https://api3.binance.com/",
    "https://api3.binance.us/",
    "https://fapi.binance.com/",
    "https://dapi.binance.com/",
  ]

This is a no go also for personal accout info like spot wallet.

So I played a round a bit.
It seamed strange that https://api.binance.com/api/v1/ticker/allPrices was working in chrome, but I was getting the stupid 451 (I am not in US) when using an importjson google extension based on https://github.com/bradjasper/ImportJSON
I installed the ImportJSON from google marketplace (still do not like it since I want to have/see control of the code) which allowed me to see the .com link in table format.
My guess would be that the .com is working, except if I use some intermediate steps which is accessing US servers somehow???
@diegomanuel can you please test the above to see if it makes sense?

@RobertSmith8
Copy link
Author

So I played a round a bit. It seamed strange that https://api.binance.com/api/v1/ticker/allPrices was working in chrome, but I was getting the stupid 451 (I am not in US) when using an importjson google extension based on https://github.com/bradjasper/ImportJSON I installed the ImportJSON from google marketplace (still do not like it since I want to have/see control of the code) which allowed me to see the .com link in table format. My guess would be that the .com is working, except if I use some intermediate steps which is accessing US servers somehow??? @diegomanuel can you please test the above to see if it makes sense?

Se post 1.
I'm able to call API Locally but unable to do it using Google script, simple test is to use this API call in a browser.
https://api.binance.com/api/v3/time

@domenan
Copy link

domenan commented Dec 4, 2022

When using the API I get this message:
"msg": "Service unavailable from a restricted location according to 'b. Eligibility' in https://www.binance.com/en/terms. Please contact customer service if you believe you received this message in error."

According the Binance terms. Binance started to restrict the use of API in the US and some other countries. As the Google server that runs apps script is in US and API request will be refused.

@diegomanuel
Copy link
Owner

When using the API I get this message: "msg": "Service unavailable from a restricted location according to 'b. Eligibility' in https://www.binance.com/en/terms. Please contact customer service if you believe you received this message in error."

According the Binance terms. Binance started to restrict the use of API in the US and some other countries. As the Google server that runs apps script is in US and API request will be refused.

Exactly that my friends... it's not a bug, sadly, instead, it seems that Binance's legal restrictions are blocking the US servers in where the apps script is run, and we can't choose or change what internal Google server/instance/region to use (as far as I know).

It makes no sense to me that Binance blocks IPs for read-only calls too...What if I'm from any other country but I travel to USA? I wouldn't be able to access and use my account while staying there? Whatever... clearly an extremelly stupid decision.

The error message also says: "Please contact customer service if you believe you received this message in error."
I think I'll try to speak with them, but I have little hope in that path.
The best shot could be to push all together as a community to make Binance change this shitty restriction, at least, allowing read-only request to access account data.

A non-trivial workaroud could be to use a "trusted proxy", changing all the defined URLs at config.gs and appsscript.json to point there and just tunnel the requests to Binance.

Sorry folks, but no easy-fix for this one, we would need to push and wait for some resolution between Binance and Google servers 😞

@akshayj12489
Copy link

I might have found a work around to get some prices but obvious not balance, open orders etc. since I don't have a US account.

replace: const SPOT_API_URL = "https://api.binance.com";

with const SPOT_API_URL = "https://api.binance.us";

and add .us to urlFetchWhitelist

  "urlFetchWhitelist": [
    "https://api.binance.com/",
    "https://api.binance.us/",
    "https://api1.binance.com/",
    "https://api1.binance.us/",
    "https://api2.binance.com/",
    "https://api2.binance.us/",
    "https://api3.binance.com/",
    "https://api3.binance.us/",
    "https://fapi.binance.com/",
    "https://dapi.binance.com/",
  ]

Hi Robert, Diego suggested that there is no easy fix around, so I'm trying the solution suggested by you.

Can you guide me where should I add urlFetchWhitelist to get the desired result.

@RobertSmith8
Copy link
Author

I might have found a work around to get some prices but obvious not balance, open orders etc. since I don't have a US account.
replace: const SPOT_API_URL = "https://api.binance.com";
with const SPOT_API_URL = "https://api.binance.us";
and add .us to urlFetchWhitelist

  "urlFetchWhitelist": [
    "https://api.binance.com/",
    "https://api.binance.us/",
    "https://api1.binance.com/",
    "https://api1.binance.us/",
    "https://api2.binance.com/",
    "https://api2.binance.us/",
    "https://api3.binance.com/",
    "https://api3.binance.us/",
    "https://fapi.binance.com/",
    "https://dapi.binance.com/",
  ]

Hi Robert, Diego suggested that there is no easy fix around, so I'm trying the solution suggested by you.

Can you guide me where should I add urlFetchWhitelist to get the desired result.

appsscript.json
https://imgur.com/a/JRgndmX

@swiftfloe
Copy link

Hi Guys,

I've found a good alternative, which is an extension you simply install on Google Sheets and you can get access to live prices from it;

https://workspace.google.com/marketplace/app/cryptosheets/898843532532

Thanks

@kezdawggy
Copy link

From an online bot i use called shrimpy.io - they had to move their servers to ireland from california to get around this issue

We have just been informed by the Binance team that they will no longer allow API access to anyone from the United States. As a result, some of our customers have received a notice from Binance that their API keys will be disabled in seven days. First and foremost, there is nothing for you to be concerned about. This will not impact the integrity of your account. However, it will require you to recreate your API keys AFTER they make their updates in seven days. Over the next week, our team will be developing updates that will connect our US-based infrastructure to other countries. As a result of that effort, we will be assigning new IPs to any customer that uses a Binance account. In seven days, we'll notify you to create your new API keys. When creating them, you will need to use the new IPs provided by Shrimpy. The old IPs will no longer work for Binance.Our team will continue to provide updates as we get closer to the migration date.

First and foremost, there is nothing for you to be concerned about. This will not impact the integrity of your account.

However, it will require you to recreate your API keys AFTER they make their updates in seven days.

Over the next week, our team will be developing updates that will connect our US-based infrastructure to other countries. As a result of that effort, we will be assigning new IPs to any customer that uses a Binance account.

In seven days, we'll notify you to create your new API keys. When creating them, you will need to use the new IPs provided by Shrimpy. The old IPs will no longer work for Binance.

Our team will continue to provide updates as we get closer to the migration date. In the mean-time, please email [email protected] if you have any questions.

The Shrimpy Team

Shrimpy

3833 E Main St PMB 4006, St. Charles, IL 60174

@RobertSmith8
Copy link
Author

RobertSmith8 commented Dec 7, 2022

Update:
https://data.binance.com can be used for getting market data.

@diegomanuel
https://binance-docs.github.io/apidocs/spot/en/#change-log

@akshayj12489
Copy link

Update: https://data.binance.com can be used for getting market data.

@diegomanuel https://binance-docs.github.io/apidocs/spot/en/#change-log

Hi Robert, can you share a sample spreadsheet if you managed to get it.

@RobertSmith8
Copy link
Author

Update: https://data.binance.com can be used for getting market data.
@diegomanuel https://binance-docs.github.io/apidocs/spot/en/#change-log

Hi Robert, can you share a sample spreadsheet if you managed to get it.

Se post 1

replace:
const SPOT_API_URL = "https://api.binance.com/";
with
const SPOT_API_URL = "https://data.binance.com/";

and add data.binance.com to urlFetchWhitelist

@akshayj12489
Copy link

Update: https://data.binance.com can be used for getting market data.
@diegomanuel https://binance-docs.github.io/apidocs/spot/en/#change-log

Hi Robert, can you share a sample spreadsheet if you managed to get it.

Se post 1

replace: const SPOT_API_URL = "https://api.binance.com/"; with const SPOT_API_URL = "https://data.binance.com/";

and add data.binance.com to urlFetchWhitelist

Made both the changes but still getting no update in 24h stats. Please have a look if possible

https://docs.google.com/spreadsheets/d/1x3yPplVXpFnIPQ-mDDGYIvWgwXmenooTh6QlyQHr4mw/edit?usp=sharing

@RobertSmith8
Copy link
Author

RobertSmith8 commented Dec 8, 2022

I'm getting price and 24h stats, but error in DEMO is "Exceeded maximum execution time (line 0)"

diegomanuel added a commit that referenced this issue Dec 10, 2022
@diegomanuel
Copy link
Owner

diegomanuel commented Dec 10, 2022

Hey folks, I've released a new version with proxy support:
https://github.com/diegomanuel/binance-to-google-sheets/releases/tag/v0.5.3

I've also created a basic proxy implementation that may be useful for someone else:
https://github.com/diegomanuel/binance-to-google-sheets-proxy

I'm closing this ticket.
Hope Binance changes his mind and we could return to normal "non-proxy" mode soon.


[#143] How to install Add-On Proxy on Mac

@cristipurdel
Copy link

https://dev.binance.vision/t/api-error-451-unavailable-for-legal-reasons/13828
data.binance.com will answer all READ-only API requests
can this bypass the proxy workaround?
I kind of gave up, wrote my own python script for binance-connector on pythonanywhere, just to have also access to the staking and wallet data

@diegomanuel
Copy link
Owner

diegomanuel commented Dec 17, 2022

https://dev.binance.vision/t/api-error-451-unavailable-for-legal-reasons/13828 data.binance.com will answer all READ-only API requests can this bypass the proxy workaround? I kind of gave up, wrote my own python script for binance-connector on pythonanywhere, just to have also access to the staking and wallet data

Didn't try data.binance.com but I'm almost sure that it doesn't support some of the add-on requests (mainly some POST ones), although they are all read-only too.
You could try it easily, just replace all the URLs at config.gs, add to appsscript.json and let USE_PROXY=false.
For now, I'm just using the proxy I've built and that's it.

Plz @cristipurdel let us know if you manage to get all the add-on functions/endpoints working with data.binance.com!

@cristipurdel
Copy link

https://dev.binance.vision/t/api-error-451-unavailable-for-legal-reasons/13828 data.binance.com will answer all READ-only API requests can this bypass the proxy workaround? I kind of gave up, wrote my own python script for binance-connector on pythonanywhere, just to have also access to the staking and wallet data

Didn't try data.binance.com but I'm almost sure that it doesn't support some of the add-on requests (mainly some POST ones), although they are all read-only too. You could try it easily, just replace all the URLs at config.gs, add to appsscript.json and let USE_PROXY=false. For now, I'm just using the proxy I've built and that's it.

Plz @cristipurdel let us know if you manage to get all the add-on functions/endpoints working with data.binance.com!

I have not tried data.binance.com with your script.
The binance-connector module (at least the non-rc 1.18.0) never complained about the stupid 451 status, neither when running it locally, nor in the cloud (pythonanywhere).

@neillamontuk
Copy link

Due to Binances changes and my inability to figure out your proxy solution i had a look about and found :
https://cryptoprices.cc
which allowed me to pull prices in USD using:
IMPORTDATA("https://cryptoprices.cc/BTC/") in google sheets...
This is not an ideal solution (although is about the right dificulty level for me) it is a website that pulls data from the coingecko API:
https://www.coingecko.com/en/api
There is a significant delay of 30-60 mins but it does provide access to a significant number of crypto/USD pairs.

@umairj
Copy link

umairj commented Feb 6, 2023

Modifying the url to https://data.binance.com worked for me.
Thanks.

const SPOT_API_URL = "https://data.binance.com"

@bhaskoro-muthohar
Copy link

Modifying the url to https://data.binance.com worked for me. Thanks.

const SPOT_API_URL = "https://data.binance.com"

Got error 404 here

@Hoochie63
Copy link

Got error 404 here

Did you add "data.binance.com" to urlFetchWhitelist?

@diegomanuel
Copy link
Owner

Reopening the issue for better visibility since there are people still having questions/problems about this.

@diegomanuel diegomanuel reopened this Mar 20, 2023
@bhaskoro-muthohar
Copy link

bhaskoro-muthohar commented Mar 20, 2023

Did you add "data.binance.com" to urlFetchWhitelist?

Got this error, when calling =BINANCE("account")
error:

Error
Error: Request failed with status: 451 (line 1876).

image

I have added "data.binance.com"

image

@The-Naken
Copy link

Hi everyone,

I believe most of us have been experiencing issues with error 451 and have had to resort to building a proxy, provided we have the knowledge to do so.

This morning (28/03/2023), I was attempting some actions on my Google Sheet and encountered the typical error 451 code. However, upon returning to my desk, I magically found that the issue had been resolved, and I was able to retrieve all the necessary data from my account.

Has anyone else experienced a similar occurrence?

I would like to express my gratitude to @diegomanuel for the amazing work and updates they have provided for us. Would it be possible to add the option to link an unlimited number of Binance accounts?

EDIT: My happiness was short-lived as I'm now back to encountering the full error 451 on my Google Sheet. I'm unsure what happened or how it was briefly working earlier.

Best regards,
Naken

@grafanaKibana
Copy link

grafanaKibana commented Oct 3, 2023

For everyone who waiting for a workaround, I found one! Take a look at the this issue where I described it:

Seems there is a simple workaround:

Just change SPOT_API_URL to "https://binance.com/" and add "https://binance.com/" to appsscript.json. Not sure it will work for a long time but it is what it is :)

P.S. Unfortunately it will not work for the USD ticker if you used it as I

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests