0

I have a link with some data link to the json file. I want in python to make a script who get the id value.

the value that I want

Can someone help me, I have done that but it keep saying that { "response": "Too many requests" }

My code :

response_API = requests.get('https://api.scratch.mit.edu/users/FlyPhoenix/') data = response_API.text print(data)

2 Answers2

0

This solution might work for you:

import json
import requests

response_API = requests.get('https://api.scratch.mit.edu/users/FlyPhoenix/')
data = response_API.text
print(json.loads(data)['id'])

print() will display the ID you want.

About { "response": "Too many requests" }:

Obviously, your rate of requests has been too high and the server is not willing to accept this. You should not seek to "dodge" this, or even try to circumvent server security settings by trying to spoof your IP, you should simply respect the server's answer by not sending too many requests. (as says in How to avoid HTTP error 429 (Too Many Requests) python)

6 crimes
  • 3
  • 3
  • It's not working, same error. It's wird that I got to many request cause I only request the json file once. I show you the entire script. https://replit.com/@FlyPhoenixjujub/Image-Loader#main.py – FlyPhoenix Feb 15 '23 at 17:45
0

Additional solution:

  1. Check if your code is not in a loop making the request over and over.
  2. if you have a dynamic IP restart your router. If not wait until you can make request again.
import requests

    def get_id():
        URL = "https://api.scratch.mit.edu/users/FlyPhoenix/"
        resp = requests.get(URL)
    
        if resp.status_code == 200:
            data_dict = resp.json()
            return (data_dict["id"])
        else:
            print("Error: request failed with status code", resp.status_code)
            
            
print (get_id())
DSgUY
  • 101
  • 6
  • I got the same error, I don't understand cause my code is not looping and I don't understand what you mean by a dynamic IP – FlyPhoenix Feb 15 '23 at 15:23
  • Check the thread in the other solution. Probably you made too many request to the link when devolping your solution so the server block you for some time. Regarding dynamic IP is when your internet service provider (ISP) change your IP every time your power on your router or after 12hs for example. – DSgUY Feb 15 '23 at 15:37
  • I tested the code above inside a while TRUE loop and never got `"Too many requests" ` – DSgUY Feb 15 '23 at 15:43