MC-API / Issues

Public issue tracker for mc-api.net
https://mc-api.net
2 stars 0 forks source link

Error 403 #17

Closed itsfolf closed 8 years ago

itsfolf commented 8 years ago

Im trying to use the mc api but I get error 403

My code: json = readUrl("http://eu.mc-api.net/v3/server/info/mc.hypixel.net");

         Gson gson = new Gson(); 
         Page page = gson.fromJson(json, Page.class);

         System.out.println(page.status);

Error: java.io.IOException: Server returned HTTP response code: 403 for URL: http://eu.mc-api.net/v3/server/info/mc.hypixel.net at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source) at java.net.URL.openStream(Unknown Source) at tx.craft.SkypeBot.JP.readUrl(JP.java:25) at tx.craft.SkypeBot.JP.send(JP.java:46) at tx.craft.SkypeBot.Bot$1.chatMessageReceived(Bot.java:34) at com.skype.ChatMessageConnectorListener.fireMessageReceived(ChatMessageConnectorListener.java:76) at com.skype.ChatMessageConnectorListener.messageReceived(ChatMessageConnectorListener.java:51) at com.skype.connector.Connector.fireMessageEvent(Connector.java:1160) at com.skype.connector.Connector.access$500(Connector.java:37) at com.skype.connector.Connector$13.run(Connector.java:1139) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source)

nathantowell commented 8 years ago

Hello. Currently @njb_said is on holidays so I'll be helping you today :)

The error is the 403 response code that our server returned. This means that the page is forbidden. This is most likely an issue with Cloudflare blocking your request(s). Have you tried another way of reading the json, perhaps try the URL and URLConnection class?

adpking commented 8 years ago

I would like to add to this by saying I'm receiving the 403 both locally and pushed to the server I'm developing for. I'm using a HttpURLConnection and a buffered reader to obtain the response data (as I did with Mojang's API previously which worked) like so BufferedReader response = BufferedReader(new InputStreamReader(connection.getInputStream())) but the reponse headers aren't very useful..

X-Frame-Options: 
SAMEORIGIN

Transfer-Encoding: 
chunked

null: 
HTTP/1.1 403 Forbidden

CF-RAY: 
259dedd8529b352a-LHR

Cache-Control: 
max-age=10

Server: 
cloudflare-nginx

Connection: 
keep-alive

Set-Cookie: 
__cfduid=df67f96d877c316d407fd587dd6ac0d751450977125; expires=Fri, 23-Dec-16 17:12:05 GMT; path=/; domain=.mc-api.net; HttpOnly

Expires: 
Thu, 24 Dec 2015 17:12:15 GMT

Date: 
Thu, 24 Dec 2015 17:12:05 GMT

Content-Type: 
text/html; charset=UTF-8

I have explicitly defined the content type as application/json on the instance of HttpURLConnection as such: connection.setRequestProperty("Content-Type", "application/json") and my URL is formatted like so: String url = String.format("https://us.mc-api.net/v3/uuid/%s/json", playerName)

Really not sure about this one but I took a look at your Java implementation and found you use a HttpResponse which might be worth trying on my end but I'd rather not have to re-factor right now. Any insight would be appreciated!

adpking commented 8 years ago

I'd also like add that I could only get it to work by falsifying the User-Agent header.

njb-said commented 8 years ago

Ah, in that case it is cloudflare blocking you for an invalid user-agent header, setting that yourself would fix it.

nathantowell commented 8 years ago

Looks like it was solved. Closing Issue

dadus33 commented 8 years ago

Well maybe you guys no longer get this issue but unfortunately I still do. It happens with the UUID API in /v3/uuid/notch. I get 403 error.

itsfolf commented 8 years ago

@dadus33 Ther's two errors, one is the path, and other the name, you should use http://mcapi.ca/uuid/player/Notch , whatever the UUID API isn't working for me at the time I'm writing this, when it gets back up the URL i give to you should work, if not look at the methods above.

dadus33 commented 8 years ago

@checkplys thanks for that but unfortunately I was trying to switch from mcapi.ca as it's downtime is just huge. What should I try?

dadus33 commented 8 years ago

Also what do you mean by wrong path or name? The user notch does exist. Also, what's wrong with the path? Seems to be working in browser: http://eu.mc-api.net/v3/uuid/Notch

itsfolf commented 8 years ago

@dadus33 On the example it shows another path at mc-api.net

dadus33 commented 8 years ago

Well this is the example: http://prntscr.com/a410jg But anyways, what should I do? Why do I keep getting 403? Please help...

nathantowell commented 8 years ago

Have you tried setting your user agent header yourself @dadus33 ? It was the fix for this issue originally. Cloudflare likes to block most requests that look like a bot attack or dos which normally don't have proper headers.

dadus33 commented 8 years ago

@ImNatho Well I'm trying to use it for the UUID fetcher of the SkinsResorer plugin. That currently uses mcapi.ca which is kinda always down -_-. Anyways, I know how to add a custom header but I just don't want to mess up the current code of the plugin as honestly, there are lots of things there I can't understand. However, I'll try, and if I don't manage to solve it I'll tell the author to change it if possible. I'll report back ASAP! Thanks for the idea anyways!

nathantowell commented 8 years ago

Can I have a link to that plugin? I might write a MC-API patch for it

dadus33 commented 8 years ago

@ImNatho Of course, it's open source on github, just search for it (SkinsRestorer by Th3Troller). By the way, it looks like I managed to edit those things myself :D

njb-said commented 8 years ago

@dadus33 On that repository it doesn't look like it uses mc-api at all https://github.com/Th3Tr0LLeR/SkinsRestorer---Maro/blob/master/src/skinsrestorer/shared/utils/MojangAPI.java#L42

ghost commented 8 years ago

@njb-said Yes, Because I don't know if it bypasses the rate limit. It would be cool to use it if it does :)

njb-said commented 8 years ago

We aren't affiliated with mcapi.ca in any way. This is mc-api.net, an entirely seperate service. Just wanted to clear that up in case anyone was confused.

ghost commented 8 years ago

Yes. When i was searching for an API i can use to bypass the limit, i saw your API. It is good, but i don't know if it has limit, or it doesn't have. it can easily be overloaded by the servers using SkinsRestorer.

itsfolf commented 8 years ago

@dadus33

Download gson and add it to your buildpath: http://central.maven.org/maven2/com/google/code/gson/gson/2.5/gson-2.5.jar Then use this class I made for you: http://pastebin.com/V0e5VHsR

With that, you can just do this: String UUID = JsonGet.getUUID("player")

dadus33 commented 8 years ago

@checkplys Thanks for the suggestion but I already managed to get it working. Anyways, I think this issued should now rest in peace. You won't get the 403 error if you use a fake user agent.

njb-said commented 8 years ago

@dadus33 As this has happened to a few people now I am going to add a message in the documentation about it until I can think of a better solution.

@Th3Tr0LLeR As for rate limiting, there isn't a "hard" rate limit on my servers that anyone is likely to hit, but it can still get throttled by mojang (not much I can about this other than proxy my traffic + add more servers) I am currently investigating if I need more servers and also looking at a way to proxy my traffic (make it use a different ip address) to fit mojang's silly rate limit.

ghost commented 8 years ago

@njb-said SkinsRestorer is used to restore the skins for the cracked servers. it requests skin data every time a new or un-cached player join. I used to use mcapi.ca, but now it gets overloaded and i don't know what to do now :D