steem-js icon indicating copy to clipboard operation
steem-js copied to clipboard

XMLHttpRequest cannot load https://api.steemit.com/. No 'Access-Control-Allow-Origin' header is present on the requested resource.

Open ghost opened this issue 7 years ago • 8 comments

I made a GET request (request that doesn't modify the blockchain) and got an error.

Expected behavior

No error is returned.

Actual behavior

XMLHttpRequest cannot load https://api.steemit.com/. 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
Origin 'null' is therefore not allowed access.
The response had HTTP status code 504.

How to reproduce

Execute get requests repeatedly until the error pops up. Occurs very rarely.

Environment information

Ubuntu 16.04

ghost avatar Jan 23 '18 07:01 ghost

All API calls are POST requests. Can you provide some sample code to reproduce this?

jnordberg avatar Jan 24 '18 00:01 jnordberg

Well basically I'm executing the code from the console on no domain (just an open browser). The error happens rarely, it's not deterministic. It's good to know that all calls are POST.

After doing some more research, it seems that the 504 code means that the API acted as a "gateway" for the blockchain and the blockchain timed out in its response. Does that seem like a reasonable explanation?

The current solution I'm trying out is to just swallow all errors from "would-be" GET requests, as they most likely indicate a network error.

Do you think this is a reasonable to handle this problem?

ghost avatar Jan 24 '18 00:01 ghost

Same sudden issue here. The API was just working fine till today for me.

The funny part is, that it only gave me problems once I deleted my browser cache.

Failed to load https://api.steemit.com/: Response to preflight 
request doesn't pass access control check: No 'Access-Control-Allow-Origin' 
header is present on the requested resource. Origin 'https://localhost:8080'
 is therefore not allowed access.

AusPrinzip avatar Jan 24 '18 19:01 AusPrinzip

It honestly just seems like the blockchain is failing to respond. I didn't have this problem before either.

ghost avatar Jan 25 '18 02:01 ghost

This is so annoying. I keep getting 504's sporadically for all types of requests. It'll just happen once every like 10 requests. I also tried using the dsteem library instead but it's the same issue. Almost certain that it's an issue with api.steemit.com.

jonching avatar Apr 16 '18 19:04 jonching

The simplest solution would be to use different node, for example: steem.api.setOptions({url: 'wss://steemd-int.steemit.com'});

BartolomeoItaliano avatar Apr 17 '18 07:04 BartolomeoItaliano

Right but I haven't found a single one that works reliably. steemd-int.steemit.com is really fast and doesn't have the 504 errors but after 5-10 minutes, the connection closes and you're unable to use it anymore in your session.

jonching avatar Apr 18 '18 01:04 jonching

Hmm... I can only suppose, but maybe you are making to many requests and to not let you overload node you'd been hold back for some time on making requests? (I don't know its only my guess)

BartolomeoItaliano avatar Apr 18 '18 07:04 BartolomeoItaliano