kandi background
Explore Kits

python-docs-samples | Code samples used on cloud.google.com | GCP library

 by   GoogleCloudPlatform Python Version: Current License: Apache-2.0

 by   GoogleCloudPlatform Python Version: Current License: Apache-2.0

Download this library from

kandi X-RAY | python-docs-samples Summary

python-docs-samples is a Python library typically used in Cloud, GCP applications. python-docs-samples has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. However python-docs-samples build file is not available. You can install using 'pip install python-docs-samples' or download it from GitHub, PyPI.
Code samples used on cloud.google.com
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • python-docs-samples has a medium active ecosystem.
  • It has 5530 star(s) with 5571 fork(s). There are 287 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 37 open issues and 2306 have been closed. On average issues are closed in 11 days. There are 27 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of python-docs-samples is current.
python-docs-samples Support
Best in #GCP
Average in #GCP
python-docs-samples Support
Best in #GCP
Average in #GCP

quality kandi Quality

  • python-docs-samples has 0 bugs and 0 code smells.
python-docs-samples Quality
Best in #GCP
Average in #GCP
python-docs-samples Quality
Best in #GCP
Average in #GCP

securitySecurity

  • python-docs-samples has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • python-docs-samples code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
python-docs-samples Security
Best in #GCP
Average in #GCP
python-docs-samples Security
Best in #GCP
Average in #GCP

license License

  • python-docs-samples is licensed under the Apache-2.0 License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
python-docs-samples License
Best in #GCP
Average in #GCP
python-docs-samples License
Best in #GCP
Average in #GCP

buildReuse

  • python-docs-samples releases are not available. You will need to build from source code and install.
  • Deployable package is available in PyPI.
  • python-docs-samples has no build file. You will be need to create the build yourself to build the component from source.
  • Installation instructions, examples and code snippets are available.
  • python-docs-samples saves you 20791 person hours of effort in developing the same functionality from scratch.
  • It has 50552 lines of code, 3295 functions and 1053 files.
  • It has high code complexity. Code complexity directly impacts maintainability of the code.
python-docs-samples Reuse
Best in #GCP
Average in #GCP
python-docs-samples Reuse
Best in #GCP
Average in #GCP
Top functions reviewed by kandi - BETA

kandi has reviewed python-docs-samples and discovered the below as its top functions. This is intended to give you an instant insight into python-docs-samples implemented functionality, and help decide if they suit your requirements.

  • Run command
    • Delete a consent store
    • Creates a consent store
    • Execute a command
  • Create devices and gateway
    • Bind a device to a gateway
    • Create a device
    • Creates a new gateway
  • Run a beam
    • Create a keras model
  • Query the collection
    • Creates a daily nearby nearline 30 days
      • Create a task in a queue
        • Sends data to a device
          • Creates a transfer between the given POSIX job
            • Create a new gateway
              • Creates a new device
                • Create a Keras model
                  • Run a tf Tensorflow on the given locations
                    • Creates a one - time transfer task
                      • Start listening for messages
                        • Convert a Spark Spark StreamingStream to a stream
                          • Parse command line arguments
                            • Publish data from a device
                              • Run the MQTT device
                                • Generates a URL for a signed URL
                                  • Transfer data from GCS to GCS compatible
                                    • Train and evaluate a keras model
                                      • Create a new machine

                                        Get all kandi verified functions for this library.

                                        Get all kandi verified functions for this library.

                                        python-docs-samples Key Features

                                        Code samples used on cloud.google.com

                                        Setup

                                        copy iconCopydownload iconDownload
                                        git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
                                        

                                        How to run a sample

                                        copy iconCopydownload iconDownload
                                        cd logging/cloud-client/
                                        

                                        App engine+Postgresql getting "Connection refused" error

                                        copy iconCopydownload iconDownload
                                        "CloudSQL warning: your action is needed to update your application and avoid potential disruptions. Please see https://cloud.google.com/sql/docs/mysql/connect-overview for additional details: ensure that the account has access to "asim800:us-central1:django-mysql-1" (and make sure there's no typo in that name). Error during createEphemeral for asim800:us-central1:django-mysql-1: googleapi: Error 403: The client is not authorized to make this request., notAuthorized"
                                        

                                        How to upload file from Google App Engine to Google Cloud Storage using Python Flask?

                                        copy iconCopydownload iconDownload
                                        from google.cloud import storage
                                        
                                        
                                        def upload_blob(bucket_name, source_file_name, destination_blob_name):
                                            """Uploads a file to the bucket."""
                                            # SOURCE:
                                            # https://cloud.google.com/storage/docs/uploading-objects#uploading-an-object
                                        
                                            # The ID of your GCS bucket
                                            # bucket_name = "your-bucket-name"
                                            # The path to your file to upload
                                            # source_file_name = "local/path/to/file"
                                            # The ID of your GCS object
                                            # destination_blob_name = "storage-object-name"
                                        
                                            storage_client = storage.Client()
                                            bucket = storage_client.bucket(bucket_name)
                                            blob = bucket.blob(destination_blob_name)
                                            blob.upload_from_filename(source_file_name)
                                            print(
                                                "File {} uploaded to {}.".format(
                                                    source_file_name, destination_blob_name
                                                )
                                            )
                                        
                                        
                                        TMP_PATH = "/tmp/"
                                        TMP_FILE_NAME = f"{TMP_PATH}file.xlsx"
                                        BUCKET_NAME = '<your-bucket-name>'
                                        
                                        
                                        with open(TMP_FILE_NAME, "w") as outfile:
                                            outfile.write("write file action goes here")
                                        upload_blob(BUCKET_NAME, TMP_FILE_NAME, "Target file path goes here...")
                                        

                                        Dataflow fails due to ERROR: Could not find a version that satisfies the requirement wheel (from versions: none)

                                        copy iconCopydownload iconDownload
                                        ndjson==0.3.1
                                        google-cloud-storage==1.31.2
                                        google-cloud-secret-manager==2.0.0
                                        pycryptodome==3.9.8
                                        

                                        GCP Cloud Composer: get_client_id.py error with required arguments

                                        copy iconCopydownload iconDownload
                                            parser.add_argument('--project_id', help='Your Project ID.')
                                            parser.add_argument(
                                                '--location', help='Region of the Cloud Composer environent.')
                                            parser.add_argument(
                                                '--composer_environment', help='Name of the Cloud Composer environment.')
                                        
                                        python test.py --project_id=you-project-id-here --location=us-central1 --composer_environment=test-composer
                                        
                                        xxxxx-xxxxxxx.apps.googleusercontent.com
                                        
                                            parser.add_argument('--project_id', help='Your Project ID.')
                                            parser.add_argument(
                                                '--location', help='Region of the Cloud Composer environent.')
                                            parser.add_argument(
                                                '--composer_environment', help='Name of the Cloud Composer environment.')
                                        
                                        python test.py --project_id=you-project-id-here --location=us-central1 --composer_environment=test-composer
                                        
                                        xxxxx-xxxxxxx.apps.googleusercontent.com
                                        
                                            parser.add_argument('--project_id', help='Your Project ID.')
                                            parser.add_argument(
                                                '--location', help='Region of the Cloud Composer environent.')
                                            parser.add_argument(
                                                '--composer_environment', help='Name of the Cloud Composer environment.')
                                        
                                        python test.py --project_id=you-project-id-here --location=us-central1 --composer_environment=test-composer
                                        
                                        xxxxx-xxxxxxx.apps.googleusercontent.com
                                        
                                        python get_client_id.py my-gcp-project us-west1 my-composer-environment-name
                                        

                                        403 Error while running cloudiot_pubsub_example_server.py code for GCP IOT Core and PUB/SUB

                                        copy iconCopydownload iconDownload
                                        python3 cloudiot_pubsub_example_server.py --project_id=project-aura-249003 --pubsub_subscription=temp --service_account_json="your_service_account_credentials.json"
                                        
                                        python3 cloudiot_pubsub_example_mqtt_device.py --project_id=my-project-id --registry_id=my-registry --device_id=device-****** --private_key_file=rsa_private.pem --algorithm=RS256 --ca_certs=roots.pem
                                        
                                        python3 cloudiot_pubsub_example_server.py --project_id=my-project-id --pubsub_subscription=my-sub-****** --service_account_json="my_credentials.json"
                                        
                                        python3 cloudiot_pubsub_example_server.py --project_id=project-aura-249003 --pubsub_subscription=temp --service_account_json="your_service_account_credentials.json"
                                        
                                        python3 cloudiot_pubsub_example_mqtt_device.py --project_id=my-project-id --registry_id=my-registry --device_id=device-****** --private_key_file=rsa_private.pem --algorithm=RS256 --ca_certs=roots.pem
                                        
                                        python3 cloudiot_pubsub_example_server.py --project_id=my-project-id --pubsub_subscription=my-sub-****** --service_account_json="my_credentials.json"
                                        
                                        python3 cloudiot_pubsub_example_server.py --project_id=project-aura-249003 --pubsub_subscription=temp --service_account_json="your_service_account_credentials.json"
                                        
                                        python3 cloudiot_pubsub_example_mqtt_device.py --project_id=my-project-id --registry_id=my-registry --device_id=device-****** --private_key_file=rsa_private.pem --algorithm=RS256 --ca_certs=roots.pem
                                        
                                        python3 cloudiot_pubsub_example_server.py --project_id=my-project-id --pubsub_subscription=my-sub-****** --service_account_json="my_credentials.json"
                                        

                                        Deploying a Django site to GCP on App Engine, connecting App Engine to Cloud SQL

                                        copy iconCopydownload iconDownload
                                        if os.getenv('GAE_APPLICATION', None):
                                            # Running on production App Engine, so connect to Google Cloud SQL using
                                            # the unix socket at /cloudsql/<your-cloudsql-connection string>
                                            DATABASES = {
                                                'default': {
                                                    'ENGINE': 'django.db.backends.mysql',
                                                    'HOST': '/cloudsql/[YOUR-CONNECTION-NAME]',
                                                    'USER': '[YOUR-USERNAME]',
                                                    'PASSWORD': '[YOUR-PASSWORD]',
                                                    'NAME': '[YOUR-DATABASE]',
                                                }
                                            }
                                        else:
                                            # Running locally so connect to either a local MySQL instance or connect to
                                            # Cloud SQL via the proxy. To start the proxy via command line:
                                            #
                                            #     $ cloud_sql_proxy -instances=[INSTANCE_CONNECTION_NAME]=tcp:3306
                                            #
                                            # See https://cloud.google.com/sql/docs/mysql-connect-proxy
                                            DATABASES = {
                                                'default': {
                                                    'ENGINE': 'django.db.backends.mysql',
                                                    'HOST': '127.0.0.1',
                                                    'PORT': '3306',
                                                    'NAME': '[YOUR-DATABASE]',
                                                    'USER': '[YOUR-USERNAME]',
                                                    'PASSWORD': '[YOUR-PASSWORD]',
                                                }
                                            }
                                        

                                        Unable to set GitHub access token

                                        copy iconCopydownload iconDownload
                                         git clone https://<MyGitHubAccount>@github.com/GoogleCloudPlatform/python-docs-samples.git
                                        
                                        $ git config --global url.git://github.com.insteadOf "https://github.com"
                                        

                                        GCP DLP(Data Loss prevention) getting "Decryption failed: the ciphertext is invalid."

                                        copy iconCopydownload iconDownload
                                        cat wrapped_key.txt | base64 -d > ciphertext.txt
                                        
                                        gcloud kms decrypt --location global --keyring <key-ring-name> --key <key-name> --plaintext-file unwrapped_secret.txt --ciphertext-file ciphertext.txt
                                        
                                        stat --printf="%s\n" unwrapped_secret.txt
                                        
                                        openssl rand 32 > secret.txt
                                        
                                        gcloud kms encrypt --location global --keyring <key-ring-name> --key \
                                        <key-name> --plaintext-file secret.txt --ciphertext-file \
                                        mysecret.txt.encrypted
                                        
                                        base64 mysecret.txt.encrypted
                                        
                                        cat wrapped_key.txt | base64 -d > ciphertext.txt
                                        
                                        gcloud kms decrypt --location global --keyring <key-ring-name> --key <key-name> --plaintext-file unwrapped_secret.txt --ciphertext-file ciphertext.txt
                                        
                                        stat --printf="%s\n" unwrapped_secret.txt
                                        
                                        openssl rand 32 > secret.txt
                                        
                                        gcloud kms encrypt --location global --keyring <key-ring-name> --key \
                                        <key-name> --plaintext-file secret.txt --ciphertext-file \
                                        mysecret.txt.encrypted
                                        
                                        base64 mysecret.txt.encrypted
                                        
                                        cat wrapped_key.txt | base64 -d > ciphertext.txt
                                        
                                        gcloud kms decrypt --location global --keyring <key-ring-name> --key <key-name> --plaintext-file unwrapped_secret.txt --ciphertext-file ciphertext.txt
                                        
                                        stat --printf="%s\n" unwrapped_secret.txt
                                        
                                        openssl rand 32 > secret.txt
                                        
                                        gcloud kms encrypt --location global --keyring <key-ring-name> --key \
                                        <key-name> --plaintext-file secret.txt --ciphertext-file \
                                        mysecret.txt.encrypted
                                        
                                        base64 mysecret.txt.encrypted
                                        
                                        cat wrapped_key.txt | base64 -d > ciphertext.txt
                                        
                                        gcloud kms decrypt --location global --keyring <key-ring-name> --key <key-name> --plaintext-file unwrapped_secret.txt --ciphertext-file ciphertext.txt
                                        
                                        stat --printf="%s\n" unwrapped_secret.txt
                                        
                                        openssl rand 32 > secret.txt
                                        
                                        gcloud kms encrypt --location global --keyring <key-ring-name> --key \
                                        <key-name> --plaintext-file secret.txt --ciphertext-file \
                                        mysecret.txt.encrypted
                                        
                                        base64 mysecret.txt.encrypted
                                        
                                        cat wrapped_key.txt | base64 -d > ciphertext.txt
                                        
                                        gcloud kms decrypt --location global --keyring <key-ring-name> --key <key-name> --plaintext-file unwrapped_secret.txt --ciphertext-file ciphertext.txt
                                        
                                        stat --printf="%s\n" unwrapped_secret.txt
                                        
                                        openssl rand 32 > secret.txt
                                        
                                        gcloud kms encrypt --location global --keyring <key-ring-name> --key \
                                        <key-name> --plaintext-file secret.txt --ciphertext-file \
                                        mysecret.txt.encrypted
                                        
                                        base64 mysecret.txt.encrypted
                                        
                                        cat wrapped_key.txt | base64 -d > ciphertext.txt
                                        
                                        gcloud kms decrypt --location global --keyring <key-ring-name> --key <key-name> --plaintext-file unwrapped_secret.txt --ciphertext-file ciphertext.txt
                                        
                                        stat --printf="%s\n" unwrapped_secret.txt
                                        
                                        openssl rand 32 > secret.txt
                                        
                                        gcloud kms encrypt --location global --keyring <key-ring-name> --key \
                                        <key-name> --plaintext-file secret.txt --ciphertext-file \
                                        mysecret.txt.encrypted
                                        
                                        base64 mysecret.txt.encrypted
                                        

                                        Trigger dag with parameters

                                        copy iconCopydownload iconDownload
                                        make_iap_request(webserver_url, client_id, method='POST', json=data)
                                        
                                        make_iap_request(webserver_url, client_id, method='POST', json={'conf': data})
                                        
                                        make_iap_request(webserver_url, client_id, method='POST', json=data)
                                        
                                        make_iap_request(webserver_url, client_id, method='POST', json={'conf': data})
                                        

                                        Community Discussions

                                        Trending Discussions on python-docs-samples
                                        • App engine+Postgresql getting &quot;Connection refused&quot; error
                                        • How to upload file from Google App Engine to Google Cloud Storage using Python Flask?
                                        • Broken DAG: [/home/airflow/gcs/dags/composer-dataproc-dag.py] cannot import name 'email'
                                        • Connect to mqtt.googleapis.com:8883 via proxy and another domain
                                        • Dataflow fails due to ERROR: Could not find a version that satisfies the requirement wheel (from versions: none)
                                        • Access google storage from compute instance with no external IP
                                        • GCP Cloud Composer: get_client_id.py error with required arguments
                                        • Issue installing zip file created by setup.py for deploying custom prediction to AI platform
                                        • 403 Error while running cloudiot_pubsub_example_server.py code for GCP IOT Core and PUB/SUB
                                        • Deploying a Django site to GCP on App Engine, connecting App Engine to Cloud SQL
                                        Trending Discussions on python-docs-samples

                                        QUESTION

                                        App engine+Postgresql getting &quot;Connection refused&quot; error

                                        Asked 2021-Oct-10 at 20:26

                                        I am a newbie trying to deploy a toy django app on the standard App engine and I am getting the following errors.

                                        Running App locally

                                        My app runs properly locally with the cloud SQL when I use 127.0.0.1 or Public IP as 'HOST' address. However, I get a this error if I use GCP connection name like this:

                                        'HOST':  '/cloudsql/asim800:us-central1:django-mysql-1'
                                        
                                        OperationalError: (2002, "Can't connect to local MySQL server through socket '/cloudsql/asim800:us-central1:django-mysql-1'
                                        

                                        Running App on GAE

                                        1. Using HOST='/cloudsql/asim800:us-central1:django-mysql-1', I get this error 2003, "Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)" - not sure why I am getting 'localhost' in the error but there seems to be something wrong with translating Google connection name to host and port information.

                                        2. Using public IP for mysql instance on the GAE results in timeout.

                                        My settings.py looks like this

                                            DATABASES = {
                                                'default': {
                                                        'ENGINE': 'django.db.backends.mysql',
                                                        'HOST': '/cloudsql/asim800:us-central1:django-mysql-1', 
                                                        'NAME': 'myproject',
                                                        'USER': 'pblogsu',
                                                        'PASSWORD': '****',
                                                }
                                            }
                                        

                                        I can see them correctly in the following log:

                                        {'database': 'myproject', 'host': '/cloudsql/asim800:us-central1:django-app1', 'password': 'pblogsu', 'user': 'hidden'}

                                        I have enabled Google Cloud SQL API. Not sure how to debug Google connection name mapping to host/port addresses. I have seen similar problem reported like here (https://github.com/GoogleCloudPlatform/python-docs-samples/issues/870) but none of the suggestions have helped me. Any help would be greatly appreciated.

                                        PS: I have edited my question substantially. Earlier I had used postgesql with very similar results.

                                        ANSWER

                                        Answered 2021-Oct-07 at 04:10

                                        Check the parameters unix_socket_directories and port on the PostgreSQL server. For your connection attempt to work

                                        • the server has to run on the same machine as the client

                                        • cloudsql/asim800:us-central1:django-app1 has to be in unix_socket_directories

                                        • port has to be 5432

                                        Source https://stackoverflow.com/questions/69474457

                                        Community Discussions, Code Snippets contain sources that include Stack Exchange Network

                                        Vulnerabilities

                                        No vulnerabilities reported

                                        Install python-docs-samples

                                        Install pip and virtualenv if you do not already have them.
                                        Install pip and virtualenv if you do not already have them.
                                        Clone this repository: git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
                                        Obtain authentication credentials. Create local credentials by running the following command and following the oauth2 flow (read more about the command here): gcloud auth application-default login Read more about Google Cloud Platform Authentication.

                                        Support

                                        Contributions welcome! See the Contributing Guide.

                                        DOWNLOAD this Library from

                                        Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                                        over 430 million Knowledge Items
                                        Find more libraries
                                        Reuse Solution Kits and Libraries Curated by Popular Use Cases
                                        Explore Kits

                                        Save this library and start creating your kit

                                        Explore Related Topics

                                        Share this Page

                                        share link
                                        Consider Popular GCP Libraries
                                        Try Top Libraries by GoogleCloudPlatform
                                        Compare GCP Libraries with Highest Support
                                        Compare GCP Libraries with Highest Quality
                                        Compare GCP Libraries with Highest Security
                                        Compare GCP Libraries with Permissive License
                                        Compare GCP Libraries with Highest Reuse
                                        Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
                                        over 430 million Knowledge Items
                                        Find more libraries
                                        Reuse Solution Kits and Libraries Curated by Popular Use Cases
                                        Explore Kits

                                        Save this library and start creating your kit

                                        • © 2022 Open Weaver Inc.