Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
def check_status_API(username, password):
    API_available = False
    
    # Inloggen en authentiseren
    my_headers = authenticate(username, password) 

    # Alleen doorgaan als my_headers beschikbaar is (authenticatie geslaagd)
    if not my_headers == {}: 
        
        # Check status Rainguru API: https://api.rainguru.nl/
        response_get_info = requests.get(f"{server}/", headers=my_headers, verify=rainguru_cert)

        #controleer reactie Rainguru API
        API_available = False
        if response_get_info.status_code == 200:
            # Succesvol: print json met status API
            print(response_get_info.json())
            API_available = True
        
        # Niet succesvol, print foutmeldingen
        elif response_get_info.status_code == 400:
            print(f"Bad request, controleer API verzoek!")
        elif response_get_info.status_code == 401:
            print(f"Gebruikersnaam en/of wachtwoord zijn onjuist!")
        elif response_get_info.status_code == 405:
            print(f"API is niet beschikbaar!")
        elif response_get_info.status_code == 500:
            print(f"Er is een interne fout opgetreden!")
        else:
            print(f"Er is een ongedefinieerde fout opgetreden!")        
    
    return API_available, my_headers

...