skip to Main Content

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

Answers


  1. 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)

    Login or Signup to reply.
  2. 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())
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search