0

Ich versuche Google Cloud-Projekt mit ResourceManager API Python-Client, aber nicht erfolgreich zu erstellen.Erstellen Sie GCP-Projekt mit Ressource-Manager-API in Python

Hier ist, was ich versucht habe:

  1. Setup-gcloud
  2. RUN gcloud Beta Auth applikations Standard-Login einrichten Anmeldeinformationen
  3. auch Kontoeinrichtung Service
  4. Ressourcenmanager api von GCP-Konsole aktivieren.

Hier ist meine Python-Code: Von views.py

from google.cloud import resource_manager 
... 

# GCP Client 
client = resource_manager.Client() 
# List down all gcp projects 
for project in client.list_projects(): 
    print(project) 
# Create a new project 
client.new_project(project_id='test-123', name='api') 

es eine Liste aller meiner GCP Projekte nach unten, aber neues Projekt nicht auf meine gcp Konsole erstellt.

Auch es gibt keinen Fehler zurück.

Hilf mir bitte!

Vielen Dank im Voraus!

Antwort

0

Erfolgreich erstellt Google Cloud-Projekt mithilfe von Google Cloud API Python-Client erstellen.

Schritte

  • Lauf gcloud Beta Auth applikations Standard-Login-Befehl Anwendung Standardanmeldeinformationen durch Login auf den Browser auf meinem gcp Konsole

Hier

  • aktivieren Sie das Resource Manager-API zu erhalten der funktionierende Python-Code:

    from googleapiclient import discovery 
    from oauth2client.client import GoogleCredentials 
    ... 
    
    
    credentials = GoogleCredentials.get_application_default() 
        service = discovery.build('cloudresourcemanager', 'v1', credentials=credentials) 
          project_body = { 
           'name': 'Api Project', 
           'projectId': 'api-9837' 
          } 
          request = service.projects().create(body=project_body) 
          request.execute() 
          pprint(request) 
    
  • Verwandte Themen