Giter Site home page Giter Site logo

googlecloudplatform / getting-started-python Goto Github PK

View Code? Open in Web Editor NEW
778.0 92.0 580.0 1.05 MB

Code samples for using Python on Google Cloud Platform

Home Page: https://cloud.google.com/python

License: Apache License 2.0

Python 53.59% HTML 13.53% Shell 29.64% Dockerfile 2.37% Makefile 0.86%
samples

getting-started-python's Introduction

Getting started with Python on Google Cloud Platform

This repository is the complete sample code for the Python Getting Started on Google Cloud Platform tutorials. Please refer to the tutorials for instructions on configuring, running, and deploying these samples.

The code for the samples is contained in individual folders in this repository.

Tutorial Folder
Getting Started bookshelf
Background Processing background
Deploying to Google Kubernetes Engine in "kubernetes-engine-samples" repo
Deploying to Google Compute Engine gce
Handling Sessions with Firestore sessions
Authenticating Users with IAP authenticating-users

Contributing changes

Licensing

getting-started-python's People

Contributors

akshaykumarpatil-tudip avatar bshaffer avatar busunkim96 avatar chck avatar crwilcox avatar dandhlee avatar dpebot avatar drigz avatar engelke avatar jonjohnsonjr avatar jphalip avatar justinbeckwith avatar kweinmeister avatar leahecole avatar markbrockettrobson avatar mcanaleta avatar medyagh avatar miketruty avatar parthea avatar renovate-bot avatar risto-mononen avatar rogerthatdev avatar rohitshah-tudip avatar ryanmats avatar spencerng avatar swatimurarka-tudip avatar tbpg avatar tristanvanech avatar vkoppaka avatar waprin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

getting-started-python's Issues

ImportError: No module named appengine.api (even after app-engine-python installation)

Hi,

I used a newly created CentOS7 VM in Google Cloud Platform to try to run the following Python code (Python version: 2.7.5):-

from google.appengine.api import urlfetch

But I got this error message:-

ImportError: No module named appengine.api

Previously, I already have already installed app-engine-python and app-engine-python-extras in gcloud. For example, if I now run this:-

yum install google-cloud-sdk-app-engine-python

I would get this to tell me that it is already installed:-

Package google-cloud-sdk-app-engine-python-194.0.0-1.noarch already installed and latest version Nothing to do

And if I now run this:-

gcloud components list

Again, I would get this to tell me that the app-engine components are already installed:-

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โ”
โ”‚                                                   Components                                                   
โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โ”ค
โ”‚      Status      โ”‚                         Name                         โ”‚            ID            โ”‚    Size   
โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
(...............................................................................)
(skipped showing other gcloud components)
(...............................................................................)
โ”‚ Installed        โ”‚ gcloud app Python Extensions                         โ”‚ app-engine-python        โ”‚   6.2 MiB 
โ”‚
โ”‚ Installed        โ”‚ gcloud app Python Extensions (Extra Libraries)       โ”‚ app-engine-python-extras โ”‚  27.8 MiB 
โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

I tried to download pip and use pip to install the stuff again, and I if I run pip freeze | grep ^google I would get this (without showing app-engine ?):-

google-api-core==0.1.4
google-auth==1.4.1
google-cloud-bigquery==0.28.0
google-cloud-bigquery-datatransfer==0.1.1
google-cloud-container==0.1.1
google-cloud-core==0.28.1
google-cloud-datastore==1.4.0
google-cloud-dns==0.28.0
google-cloud-firestore==0.28.0
google-cloud-language==1.0.1
google-cloud-monitoring==0.28.1
google-cloud-speech==0.30.0
google-cloud-trace==0.17.0
google-cloud-translate==1.3.1
google-cloud-vision==0.29.0
google-compute-engine==2.7.6
google-gax==0.15.16
google-resumable-media==0.3.1
googleapis-common-protos==1.5.3

How can I get it solved? I just want to run from google.appengine.api import urlfetch successfully.

Thanks in advance!

The More button is not More, it is Next

Don't mean to be a pain the neck but the more button should bring new items and add to the current showing list.
but instead it shows Next page with no option to show Previous, can we have either a Previous button or make More button a real more ? (append more to the current showing list)

pubsub gcloud example not working: ImportError: No module named pkg_resource

Downloaded the gcloud lib, imported it. Very sad.

(/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py:263)
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 96, in LoadObject
import(cumulative_path)
File "/base/data/home/apps/sbucket-bot-1/1.394392579757390208/api/oauth/slack.py", line 8, in
from lib.gcloud import pubsub
File "/base/data/home/apps/s
bucket-bot-1/1.394392579757390208/lib/gcloud/init.py", line 17, in
from pkg_resources import get_distribution
ImportError: No module named pkg_resources

Unable to deploy app, Can't connect to MySQL server on 'localhost' ([Errno 2] No such file or directory)

Hi there,
I was following the Gcloud python tutorial and trying to learn how to use cloud SQL. I was able to use the cloud SQL proxy to run the instance locally. However, when trying to deploy the app online, I was given the error message shown in title.
I have googled this question a bit and enabled all the APIs and services required. I have also repeated the steps several times with a new project each time. I hope someone can give me a clue to solve this problem.

HTTP GET /books/id/delete modifies server state.

According to the HTTP standard, HTTP GET requests must not modify server state.
The delete controller modifies server state with a simple GET. This is wrong. Bots will delete books unintentionally. We should switch the request to a POST.

More Button still doesn't work

I opened this issue it has been marked as solved, I just deleted everything and pulled the project. and I still get this error in both local and live .

gcloud.exceptions.BadRequest
gcloud.exceptions.BadRequest: 400 com.google.protobuf.InvalidProtocolBufferException: Error parsing protocol message

Traceback (most recent call last)
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/medya/.local/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/medya/.local/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/medya/workspace/getting-started-python/2-structured-data/bookshelf/crud.py", line 29, in list
books, next_page_token = get_model().list(cursor=token)
File "/home/medya/workspace/getting-started-python/2-structured-data/bookshelf/model_datastore.py", line 56, in list
entities, more_results, cursor = it.next_page()
File "/home/medya/.local/lib/python3.4/site-packages/gcloud/datastore/query.py", line 424, in next_page
transaction_id=transaction and transaction.id,
File "/home/medya/.local/lib/python3.4/site-packages/gcloud/datastore/connection.py", line 271, in run_query
_datastore_pb2.RunQueryResponse)
File "/home/medya/.local/lib/python3.4/site-packages/gcloud/datastore/connection.py", line 117, in _rpc
data=request_pb.SerializeToString())
File "/home/medya/.local/lib/python3.4/site-packages/gcloud/datastore/connection.py", line 94, in _request
raise make_exception(headers, error_status.message, use_json=False)
gcloud.exceptions.BadRequest: 400 com.google.protobuf.InvalidProtocolBufferException: Error parsing protocol message
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.

You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:

dump() shows all variables in the frame
dump(obj) dumps all that's known about the object
Brought to you by DON'T PANIC, your friendly Werkzeug powered traceback interpreter.

and if you add more books, it will give you this error:

binascii.Error
binascii.Error: Incorrect padding

Traceback (most recent call last)
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/medya/.local/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/medya/.local/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/medya/workspace/getting-started-python/2-structured-data/bookshelf/crud.py", line 29, in list
books, next_page_token = get_model().list(cursor=token)
File "/home/medya/workspace/getting-started-python/2-structured-data/bookshelf/model_datastore.py", line 56, in list
entities, more_results, cursor = it.next_page()
File "/home/medya/.local/lib/python3.4/site-packages/gcloud/datastore/query.py", line 407, in next_page
pb.start_cursor = base64.urlsafe_b64decode(start_cursor)
File "/usr/lib/python3.4/base64.py", line 135, in urlsafe_b64decode
return b64decode(s)
File "/usr/lib/python3.4/base64.py", line 90, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.

You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:

dump() shows all variables in the frame
dump(obj) dumps all that's known about the object

cannot determine project ID (6-pubsub)

When running 'psqworker main.books_queue' in the pubsub tutorial, I have received the error "No project ID could be determined from the Cloud SDK configuration. Consider running gcloud config set project or setting the GOOGLE_CLOUD_PROJECT environment variable".

I have already run gcloud config before and was able to complete previous tutorials. Would anyone know how I can address this?

can't loggin

I deploy app 3-binary-data and it work great.when i deploy 4-auth app and click My Books,I login with my google account,it appears:

An internal error occurred:
'profile'
See logs for full stacktrace.

2016-11-04 07:33:57 default[20161103t052819] File "/home/vmagent/app/bookshelf/crud.py", line 66, in list_mine
2016-11-04 07:33:57 default[20161103t052819] user_id=session['profile']['id'],
2016-11-04 07:33:57 default[20161103t052819] File "/env/lib/python3.4/site-packages/werkzeug/local.py", line 373, in
2016-11-04 07:33:57 default[20161103t052819] getitem = lambda x, i: x._get_current_object()[i]
2016-11-04 07:33:57 default[20161103t052819] KeyError: 'profile'

Any idea?

Book listing in Compute Engine and Datastore not working as expected

Creating more than 10 books in Datastore currently results in a TypeError with the following message when listing Books:

An internal error occurred:
character mapping must return integer, None or unicode
See logs for full stacktrace.

I've tested and observed this using the GCE sample code. I expect it would be identical in the others as the relevant code is the same across App Engine, Container Engine and Compute Engine.

To reproduce:

1 - Deploy the Compute Engine version with Datastore
2 - Create 11 Book entries
3 - Visit the URL to list the books
4 - Scroll down to the bottom and click 'More'

Cannot clone git synced repo from google cloud source repository

Hi there,
I'm trying to deploy a google cloud source repository to my deployed instance.

I'm trying (this)[https://github.com/GoogleCloudPlatform/getting-started-python/blob/steps/7-gce/gce/startup-script.sh#L45]

git clone https://source.developers.google.com/p/$PROJECTID/r/[YOUR_REPO_NAME] /opt/app

But it does not work. If I log into the instance and try it manually (as root), it asks me to refresh my credentials as a user.

This is git synced repo.

Please advice

bookshelf worker gives futures error

when I deploy the bookshelf-worker on GKE, the pods come up with the following error:

"22:19:21 worker.1 | AttributeError: 'StreamingPullFuture' object has no attribute 'future'

the frontend app works just fine under the same GKE cluster (same docker image, etc)

Error: google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS

(env) C:\Users\mramswaroop\AppData\Local\Google\Cloud SDK\getting-started-python\7-gce>python main.py

Traceback (most recent call last):
  File "main.py", line 19, in <module>
    app = bookshelf.create_app(config)
  File "C:\Users\mramswaroop\AppData\Local\Google\Cloud SDK\getting-started-python\7-gce\bookshelf\__init__.py", line 40, in create_app
    client = google.cloud.logging.Client(app.config['PROJECT_ID'])
  File "C:\Users\MRAMSW~1\AppData\Local\Google\CLOUDS~1\GETTIN~1\7-gce\env\lib\site-packages\google\cloud\logging\client.py", line 104, in __init__
    project=project, credentials=credentials, _http=_http)
  File "C:\Users\MRAMSW~1\AppData\Local\Google\CLOUDS~1\GETTIN~1\7-gce\env\lib\site-packages\google\cloud\client.py", line 216, in __init__
    Client.__init__(self, credentials=credentials, _http=_http)
  File "C:\Users\MRAMSW~1\AppData\Local\Google\CLOUDS~1\GETTIN~1\7-gce\env\lib\site-packages\google\cloud\client.py", line 129, in __init__
    credentials, _ = google.auth.default()
  File "C:\Users\MRAMSW~1\AppData\Local\Google\CLOUDS~1\GETTIN~1\7-gce\env\lib\site-packages\google\auth\_default.py", line 317, in default
    raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started
(env) C:\Users\mramswaroop\AppData\Local\Google\Cloud SDK\getting-started-python\7-gce>honcho start -f ./procfile worker bookshelf
18:33:29 system      | worker.1 started (pid=21680)
18:33:29 system      | bookshelf.1 started (pid=26396)
18:33:30 system      | bookshelf.1 stopped (rc=1)
18:33:30 system      | sending SIGTERM to worker.1 (pid 21680)
18:33:30 system      | worker.1 stopped (rc=4294967295)

my config.py


$ cat config.py
Copyright 2015 Google Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

"""
This file contains all of the configuration values for the application.
Update this file with the values for your specific Google Cloud project.
You can create and manage projects at https://console.developers.google.com
"""

import os

The secret key is used by Flask to encrypt session cookies.
SECRET_KEY = 'secret'

There are three different ways to store the data in the application.
You can choose 'datastore', 'cloudsql', or 'mongodb'. Be sure to
configure the respective settings for the one you choose below.
You do not have to configure the other data backends. If unsure, choose
'datastore' as it does not require any additional configuration.
DATA_BACKEND = 'datastore'

Google Cloud Project ID. This can be found on the 'Overview' page at
https://console.developers.google.com
PROJECT_ID = 'python-bookshelf-gce-app'

CloudSQL & SQLAlchemy configuration
Replace the following values the respective values of your Cloud SQL
instance.
CLOUDSQL_USER = 'root'
CLOUDSQL_PASSWORD = 'your-cloudsql-password'
CLOUDSQL_DATABASE = 'bookshelf'
Set this value to the Cloud SQL connection name, e.g.
"project:region:cloudsql-instance".
You must also update the value in app.yaml.
CLOUDSQL_CONNECTION_NAME = 'your-cloudsql-connection-name'

The CloudSQL proxy is used locally to connect to the cloudsql instance.
To start the proxy, use:

$ cloud_sql_proxy -instances=your-connection-name=tcp:3306

Port 3306 is the standard MySQL port. If you need to use a different port,
change the 3306 to a different port number.

Alternatively, you could use a local MySQL instance for testing.
LOCAL_SQLALCHEMY_DATABASE_URI = (
'mysql+pymysql://{user}:{password}@127.0.0.1:3306/{database}').format(
user=CLOUDSQL_USER, password=CLOUDSQL_PASSWORD,
database=CLOUDSQL_DATABASE)

When running on App Engine a unix socket is used to connect to the cloudsql
instance.
LIVE_SQLALCHEMY_DATABASE_URI = (
'mysql+pymysql://{user}:{password}@localhost/{database}'
'?unix_socket=/cloudsql/{connection_name}').format(
user=CLOUDSQL_USER, password=CLOUDSQL_PASSWORD,
database=CLOUDSQL_DATABASE, connection_name=CLOUDSQL_CONNECTION_NAME)

if os.environ.get('GAE_INSTANCE'):
SQLALCHEMY_DATABASE_URI = LIVE_SQLALCHEMY_DATABASE_URI
else:
SQLALCHEMY_DATABASE_URI = LOCAL_SQLALCHEMY_DATABASE_URI

Mongo configuration
If using mongolab, the connection URI is available from the mongolab control
panel. If self-hosting on compute engine, replace the values below.
MONGO_URI = 'mongodb://user:password@host:27017/database'

Google Cloud Storage and upload settings.
Typically, you'll name your bucket the same as your project. To create a
bucket:

$ gsutil mb gs://

You also need to make sure that the default ACL is set to public-read,
otherwise users will not be able to see their upload images:

$ gsutil defacl set public-read gs://

You can adjust the max content length and allow extensions settings to allow
larger or more varied file types if desired.
CLOUD_STORAGE_BUCKET = 'sample-bookshelf-bucket'
MAX_CONTENT_LENGTH = 8 * 1024 * 1024
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])

OAuth2 configuration.
This can be generated from the Google Developers Console at
https://console.developers.google.com/project/_/apiui/credential.
Note that you will need to add all URLs that your application uses as
authorized redirect URIs. For example, typically you would add the following:

If you receive a invalid redirect URI error review you settings to ensure
that the current URI is allowed.
GOOGLE_OAUTH2_CLIENT_ID =
'724249272391-f81%%%^^^$$$##mab29lmo2obof.apps.googleusercontent.com'
GOOGLE_OAUTH2_CLIENT_SECRET = 'e8%$#2323%fnPn3DvO95GHOlB'

Can't connect to MySQL server on 'localhost'

I am having an issue with my flexible python app deployment connecting to the cloud sql instance. It is the same issue as posted here: #92

Here is the error I receive:
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on 'localhost' ([Errno 2] No such file or directory)")
"

  • I have setup a MySQL Second Generation instance.
  • It is working fine when I run the application locally and connect through the proxy.
  • I have the following flag set in my service.yaml:
beta_settings:
cloud_sql_instances: "project:us-central1:dbinstance"

Limit OAuth 2 Client to a Google Apps Domain

I'd like to use this code as a base for a small python package I want to build in my work environment, but it has to be limited in accessibility to only gmail accounts within our GSuite Work domain. In searching for a way to tweak the OAuth client, I found this on Stackoverflow:

google = oauth.remote_app('google', base_url='https://www.google.com/accounts/', authorize_url='https://accounts.google.com/o/oauth2/auth', request_token_url=None, request_token_params={'scope': 'https://www.googleapis.com/auth/userinfo.email', 'response_type': 'code', 'hd':'domain.com'}, access_token_url='https://accounts.google.com/o/oauth2/token', access_token_method='POST', access_token_params={'grant_type': 'authorization_code'}, consumer_key=GOOGLE_CLIENT_ID, consumer_secret=GOOGLE_CLIENT_SECRET)

The request_token_params dictionary permits an hd variable where you can specify the domain to lock it down to.

Where would I put this kind of variable in the Bookshelf project to practice? Would it be under service_account.py in windows directory env\Lib\site-packages\oauth2client, or somewhere else?

Thank you for your help!!!

cannot run main.py in 7-gce: HttpAccessTokenRefreshError: No JSON object could be decoded

I follow the instructions on https://cloud.google.com/python/getting-started/run-on-compute-engine
(+ added my client ID and client secret)

(env) steren@steren-tests-error-gce:~/getting-started-python/7-gce$ python main.py
INFO:oauth2client.client:Attempting refresh to obtain initial access_token
Traceback (most recent call last):
File "main.py", line 28, in
books_queue = bookshelf.tasks.get_books_queue()
File "/home/steren/getting-started-python/7-gce/bookshelf/tasks.py", line 33, in get_books_queue
client, 'books', extra_context=current_app.app_context)
File "/home/steren/getting-started-python/7-gce/env/local/lib/python2.7/site-packages/psq/queue.py", line 40, in init
self.topic = self._get_or_create_topic()
File "/home/steren/getting-started-python/7-gce/env/local/lib/python2.7/site-packages/psq/queue.py", line 50, in _get_or_create_topic
if not topic.exists():
File "/home/steren/getting-started-python/7-gce/env/local/lib/python2.7/site-packages/gcloud/pubsub/topic.py", line 144, in exists
client.connection.api_request(method='GET', path=self.path)
File "/home/steren/getting-started-python/7-gce/env/local/lib/python2.7/site-packages/gcloud/connection.py", line 335, in api_request
target_object=_target_object)
File "/home/steren/getting-started-python/7-gce/env/local/lib/python2.7/site-packages/gcloud/connection.py", line 236, in _make_request
return self._do_request(method, url, headers, data, target_object)
File "/home/steren/getting-started-python/7-gce/env/local/lib/python2.7/site-packages/gcloud/connection.py", line 265, in _do_request
body=data)
File "/home/steren/getting-started-python/7-gce/env/local/lib/python2.7/site-packages/oauth2client/client.py", line 572, in new_request
self._refresh(request_orig)
File "/home/steren/getting-started-python/7-gce/env/local/lib/python2.7/site-packages/oauth2client/gce.py", line 94, in _refresh
status=response.status)
oauth2client.client.HttpAccessTokenRefreshError: No JSON object could be decoded

Auth issue

Going through the tutorial and everything went fine until section 4-auth. I deployed it, and when I try to log in, I get '502 Bad Gateway'. I didn't change anything. One thing in the tutorial I did have to change in the settings for authorized redirect uri, it wasn't working with https://....appspot.com, but did work when I changed it to http://.....appspot.com

docker build failed for optional-container-engine

ocker build -t gcr.io/google.com/cloud-solutions-gce/bookshelf .
Sending build context to Docker daemon 89.6 kB
Step 1 : FROM gcr.io/google_appengine/python
---> a2511b33fad9
Step 2 : RUN virtualenv /env
---> Using cache
---> 6cef78fddb91
Step 3 : ENV VIRTUAL_ENV /env
---> Using cache
---> e2ec45b681ea
Step 4 : ENV PATH /env/bin:$PATH
---> Using cache
---> 09b07145da08
Step 5 : ADD requirements.txt /app/requirements.txt
---> Using cache
---> 1eed1d3b4f90
Step 6 : RUN pip install -r /app/requirements.txt
---> Running in 1ef4285f3e93
Collecting Flask==0.11.1 (from -r /app/requirements.txt (line 1))
Downloading Flask-0.11.1-py2.py3-none-any.whl (80kB)
Collecting gcloud==0.18.1 (from -r /app/requirements.txt (line 2))
Downloading gcloud-0.18.1.tar.gz (435kB)
Collecting gunicorn==19.6.0 (from -r /app/requirements.txt (line 3))
Downloading gunicorn-19.6.0-py2.py3-none-any.whl (114kB)
Collecting oauth2client==3.0.0 (from -r /app/requirements.txt (line 4))
Downloading oauth2client-3.0.0.tar.gz (77kB)
Collecting mock==2.0.0 (from -r /app/requirements.txt (line 5))
Downloading mock-2.0.0-py2.py3-none-any.whl (56kB)
Collecting Flask-SQLAlchemy==2.1 (from -r /app/requirements.txt (line 6))
Downloading Flask-SQLAlchemy-2.1.tar.gz (95kB)
Collecting PyMySQL==0.7.8 (from -r /app/requirements.txt (line 7))
Downloading PyMySQL-0.7.8-py2-none-any.whl (79kB)
Collecting Flask-PyMongo==0.4.1 (from -r /app/requirements.txt (line 8))
Downloading Flask_PyMongo-0.4.1-py2-none-any.whl
Collecting PyMongo==3.3.0 (from -r /app/requirements.txt (line 9))
Downloading pymongo-3.3.0-cp27-cp27mu-manylinux1_x86_64.whl (339kB)
Collecting six==1.10.0 (from -r /app/requirements.txt (line 10))
Downloading six-1.10.0-py2.py3-none-any.whl
Collecting requests[security]==2.11.1 (from -r /app/requirements.txt (line 11))
Downloading requests-2.11.1-py2.py3-none-any.whl (514kB)
Collecting honcho==0.7.1 (from -r /app/requirements.txt (line 12))
Downloading honcho-0.7.1-py2.py3-none-any.whl
Collecting psq==0.4.0 (from -r /app/requirements.txt (line 13))
Downloading psq-0.4.0-py2.py3-none-any.whl
Collecting itsdangerous>=0.21 (from Flask==0.11.1->-r /app/requirements.txt (line 1))
Downloading itsdangerous-0.24.tar.gz (46kB)
Collecting Jinja2>=2.4 (from Flask==0.11.1->-r /app/requirements.txt (line 1))
Downloading Jinja2-2.8-py2.py3-none-any.whl (263kB)
Collecting Werkzeug>=0.7 (from Flask==0.11.1->-r /app/requirements.txt (line 1))
Downloading Werkzeug-0.11.11-py2.py3-none-any.whl (306kB)
Collecting click>=2.0 (from Flask==0.11.1->-r /app/requirements.txt (line 1))
Downloading click-6.6.tar.gz (283kB)
Collecting httplib2>=0.9.1 (from gcloud==0.18.1->-r /app/requirements.txt (line 2))
Downloading httplib2-0.9.2.zip (210kB)
Collecting googleapis-common-protos (from gcloud==0.18.1->-r /app/requirements.txt (line 2))
Downloading googleapis-common-protos-1.3.0.tar.gz
Collecting protobuf!=3.0.0.b2.post1,>=3.0.0b2 (from gcloud==0.18.1->-r /app/requirements.txt (line 2))
Downloading protobuf-3.0.0-py2.py3-none-any.whl (342kB)
Collecting grpcio>=1.0rc1 (from gcloud==0.18.1->-r /app/requirements.txt (line 2))
Downloading grpcio-1.0.0-cp27-cp27mu-manylinux1_x86_64.whl (4.7MB)
Collecting google-gax>=0.12.3 (from gcloud==0.18.1->-r /app/requirements.txt (line 2))
Downloading google-gax-0.12.5.tar.gz
Collecting gax-google-pubsub-v1>=0.8.0 (from gcloud==0.18.1->-r /app/requirements.txt (line 2))
Downloading gax-google-pubsub-v1-0.8.1.tar.gz
Collecting grpc-google-pubsub-v1>=0.8.0 (from gcloud==0.18.1->-r /app/requirements.txt (line 2))
Downloading grpc-google-pubsub-v1-0.8.1.tar.gz
Collecting gax-google-logging-v2>=0.8.0 (from gcloud==0.18.1->-r /app/requirements.txt (line 2))
Downloading gax-google-logging-v2-0.8.1.tar.gz
Collecting grpc-google-logging-v2>=0.8.0 (from gcloud==0.18.1->-r /app/requirements.txt (line 2))
Downloading grpc-google-logging-v2-0.8.1.tar.gz
Collecting pyasn1>=0.1.7 (from oauth2client==3.0.0->-r /app/requirements.txt (line 4))
Downloading pyasn1-0.1.9-py2.py3-none-any.whl
Collecting pyasn1-modules>=0.0.5 (from oauth2client==3.0.0->-r /app/requirements.txt (line 4))
Downloading pyasn1_modules-0.0.8-py2.py3-none-any.whl
Collecting rsa>=3.1.4 (from oauth2client==3.0.0->-r /app/requirements.txt (line 4))
Downloading rsa-3.4.2-py2.py3-none-any.whl (46kB)
Collecting funcsigs>=1; python_version < "3.3" (from mock==2.0.0->-r /app/requirements.txt (line 5))
Downloading funcsigs-1.0.2-py2.py3-none-any.whl
Collecting pbr>=0.11 (from mock==2.0.0->-r /app/requirements.txt (line 5))
Downloading pbr-1.10.0-py2.py3-none-any.whl (96kB)
Collecting SQLAlchemy>=0.7 (from Flask-SQLAlchemy==2.1->-r /app/requirements.txt (line 6))
Downloading SQLAlchemy-1.0.15.tar.gz (4.8MB)
Collecting pyOpenSSL>=0.13; extra == "security" (from requests[security]==2.11.1->-r /app/requirements.txt (line 11))
Downloading pyOpenSSL-16.1.0-py2.py3-none-any.whl (43kB)
Collecting ndg-httpsclient; extra == "security" (from requests[security]==2.11.1->-r /app/requirements.txt (line 11))
Downloading ndg_httpsclient-0.4.2.tar.gz
Collecting retrying<2.0.0,>=1.0.0 (from psq==0.4.0->-r /app/requirements.txt (line 13))
Downloading retrying-1.3.3.tar.gz
Collecting colorlog<3.0.0,>=2.6.0 (from psq==0.4.0->-r /app/requirements.txt (line 13))
Downloading colorlog-2.7.0-py2.py3-none-any.whl
Collecting MarkupSafe (from Jinja2>=2.4->Flask==0.11.1->-r /app/requirements.txt (line 1))
Downloading MarkupSafe-0.23.tar.gz
Collecting grpc>=1.0.0 (from googleapis-common-protos->gcloud==0.18.1->-r /app/requirements.txt (line 2))
Could not find a version that satisfies the requirement grpc>=1.0.0 (from googleapis-common-protos->gcloud==0.18.1->-r /app/requirements.txt (line 2)) (from versions: 0.3.post10, 0.3.post11, 0.3.post12, 0.3.post13, 0.3.post14, 0.3.po
st15, 0.3.post16, 0.3.post17, 0.3.post18, 0.3.post19)
No matching distribution found for grpc>=1.0.0 (from googleapis-common-protos->gcloud==0.18.1->-r /app/requirements.txt (line 2))
The command '/bin/sh -c pip install -r /app/requirements.txt' returned a non-zero code: 1

400 The Cloud Datastore API is not enabled for the project

Hey guys I did everything step by step, from a fresh installation, and redid at least 3 times to confirm.
each time I get this error for 2-structured-data
for both localhost and also when I deploy it in appspot
in appspot it shows:
An internal error occurred: 400 The Cloud Datastore API is not enabled for the project .... See logs for full stacktrace.

and in localhost it shows:

gcloud.exceptions.BadRequest
gcloud.exceptions.BadRequest: 400 The Cloud Datastore API is not enabled for the project river-daylight-128422

Traceback (most recent call last)
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/medya/.local/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/medya/.local/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/medya/workspace/getting-started-python/2-structured-data/bookshelf/crud.py", line 26, in list
books, next_page_token = get_model().list(cursor=token)
File "/home/medya/workspace/getting-started-python/2-structured-data/bookshelf/model_datastore.py", line 56, in list
entities, more_results, cursor = it.next_page()
File "/home/medya/.local/lib/python3.4/site-packages/gcloud/datastore/query.py", line 424, in next_page
transaction_id=transaction and transaction.id,
File "/home/medya/.local/lib/python3.4/site-packages/gcloud/datastore/connection.py", line 271, in run_query
_datastore_pb2.RunQueryResponse)
File "/home/medya/.local/lib/python3.4/site-packages/gcloud/datastore/connection.py", line 117, in _rpc
data=request_pb.SerializeToString())
File "/home/medya/.local/lib/python3.4/site-packages/gcloud/datastore/connection.py", line 94, in _request
raise make_exception(headers, error_status.message, use_json=False)
gcloud.exceptions.BadRequest: 400 The Cloud Datastore API is not enabled for the project river-daylight-128422
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.

You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:

dump() shows all variables in the frame
dump(obj) dumps all that's known about the object

and for the record, I did create a service account json crediential and downloaded it, but the tutorial never said where should I put that json file.

Connection loss during query while running model_cloudsql.py

Hi team,
When I try to run the code in bookself\model_cloudsql.py in a window VM, it shows the error as below:

CR.CR_SERVER_LOST, "Lost connection to MySQL server during query")

sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2013, 'Lost connection to MySQL server during query') (Background on this error at: http://sqlalche.me/e/e3q8)

I have already set up the config.py and app.yaml as tutorial instructed.

How can I solve this issue and complete the task with my PostgreSQL?

Best regards,
Ka Wing

Session cookie too big

How can I shrink session cookies? I am trying to authenticate users in the 4-auth directory but I cannot because the session cookie is too large. In init.py the _request_user_info() method gets the information and stores it in session. I tried to limit the data by only grabbing the displayName like so: profile = json.loads(content.decode('utf-8'))
session['profile'] = {'displayName': profile['displayName']}; But this doesn't seem to change the size of the cookie at all. Any idea how I can shrink/store the cookies? Also I am not looking to create a centralized database to store sessions securely.

problem with procfile file name

Trying to deploy the 6-pub-sub example i found a deploy error

ERROR: (gcloud.app.deploy) Error Response: [9]
Application startup error:
2018-09-06 15:00:38 [1] [ERROR] Procfile does not exist or is not a file

In this case, I changed file name from "procfile" to "Procfile" and it deployed correctly

"Can't connect to MySQL server on 'localhost' ([Errno 2] No such file or directory)"

This issue has been highlighted twice before, however is still present with the current tutorial and codebase. The application works fine in localhost through the proxy, however deploying to an app engine causes the error.

Error returned: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on 'localhost' ([Errno 2] No such file or directory)")

This was highlighted #126 and #92 . Both issues are closed, however the stock tutorial is still yielding this error.

I am encountering the same error with the actual application that I would like to deploy (not the tutorial). Both work in localhost mode, and I have tried starting brand new projects, etc.

Can't connect to MySQL server

I set this up on my local machine with CloudSQL and it works great, but when I pushed to AppEngine with gcloud app deploy and go to the resulting webpage, I get:

(pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)")

Any idea what's up?

More Button doesn't work

if you add more than 10 books and then click on "more" on 2-structured-data$ and 3-binary-data

and I get this error:

gcloud.exceptions.BadRequest
gcloud.exceptions.BadRequest: 400 com.google.protobuf.InvalidProtocolBufferException: Error parsing protocol message

Traceback (most recent call last)
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/medya/.local/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/medya/.local/lib/python3.4/site-packages/flask/_compat.py", line 33, in reraise
raise value
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/medya/.local/lib/python3.4/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/medya/workspace/getting-started-python/3-binary-data/bookshelf/crud.py", line 48, in list
books, next_page_token = get_model().list(cursor=token)
File "/home/medya/workspace/getting-started-python/3-binary-data/bookshelf/model_datastore.py", line 53, in list
entities, more_results, cursor = it.next_page()
File "/home/medya/.local/lib/python3.4/site-packages/gcloud/datastore/query.py", line 424, in next_page
transaction_id=transaction and transaction.id,
File "/home/medya/.local/lib/python3.4/site-packages/gcloud/datastore/connection.py", line 271, in run_query
_datastore_pb2.RunQueryResponse)
File "/home/medya/.local/lib/python3.4/site-packages/gcloud/datastore/connection.py", line 117, in _rpc
data=request_pb.SerializeToString())
File "/home/medya/.local/lib/python3.4/site-packages/gcloud/datastore/connection.py", line 94, in _request
raise make_exception(headers, error_status.message, use_json=False)
gcloud.exceptions.BadRequest: 400 com.google.protobuf.InvalidProtocolBufferException: Error parsing protocol message
The debugger caught an exception in your WSGI application. You can now look at the traceback which led to the error.
To switch between the interactive traceback and the plaintext one, you can click on the "Traceback" headline. From the text traceback you can also create a paste of it. For code execution mouse-over the frame you want to debug and click on the console icon on the right side.

You can execute arbitrary Python code in the stack frames and there are some extra helpers available for introspection:

dump() shows all variables in the frame
dump(obj) dumps all that's known about the object

Add HTTPS option in the optional-kubernetes-engine tutorial

Building Python app engine is very easy, switch to https (enterprise secure option) is very easy don't need a special tutorial.

In a perfect world, switch K8s from HTTP to HTTPS should be as easy as for App Engine, but K8s (optional-kubernetes-engine) the complexity level is much higher, requires more complex load balancer, SSL, DNS setup.

K8s is very powerful but difficult to adopt due to extra setup and difficult local complexity, with this extra example IMHO more enterprise users will be able to adopt GCP Kubernetes Engine.

My Books tab error

I have followed instructions under 4-auth folder.
When clicking My Books tab, I am having this error

An internal error occurred:
'profile'
See logs for full stacktrace.

Tried @jonparrott suggestion on this issue:
#95

But gave me this error :
An internal error occurred:
'Request' object has no attribute 'session'
See logs for full stacktrace.

Invalid request when trying to connect after deployment

Hi,

I have followed the Bookshelf tutorial twice and still gets the same error, on my local machine I can connect fine and it works as intended, but once deployed I can't connect anymore, I click on the login button and it just shows me a blank page saying "Invalid request", looking at the browser logs it tells me :

oauth2callback:1 Failed to load resource: the server responded with a status of 400 (BAD REQUEST)

And looking att the Logging in the Google Cloud console I have this error:

{ httpRequest: { latency: "0.002s" referer: "-" remoteIp: "145.243.200.0" requestMethod: "GET" requestUrl: "/oauth2callback?state=%7B%22csrf_token%22:%20%2226cc91a669ebae7610217aae7b8d2005d4e316c15ca937a1fd863398fa6629d6%22,%20%22return_url%22:%20%22http://python-bookshelf-app-233609.appspot.com/books/%22%7D&code=4/BgG8KhTW-YYD-HfFpUFr-zMq91FIc-HpO37CxMMW1x-sDMbKNiOtZwX1pCzDdxdHwHByc3kXLHixodWxtoSLEyI&scope=email%20profile%20https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/userinfo.profile" responseSize: "15" status: 400 userAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36" } insertId: "15moetfg3fb6nzr" jsonPayload: { appLatencySeconds: "0.000" httpRequest: { protocol: "HTTP/1.1" } latencySeconds: "0.002" trace: "dc2baf75b794faea437c4cf98e3ebb94" } labels: { appengine.googleapis.com/instance_name: "aef-default-20190306t151610-gh20" appengine.googleapis.com/trace_id: "dc2baf75b794faea437c4cf98e3ebb94" compute.googleapis.com/resource_id: "7209627706937469195" compute.googleapis.com/resource_name: "92d83ed0a168" compute.googleapis.com/zone: "europe-west3-a" } logName: "projects/python-bookshelf-app-233609/logs/appengine.googleapis.com%2Fnginx.request" receiveTimestamp: "2019-03-07T09:52:55.810033951Z" resource: { labels: { module_id: "default" project_id: "python-bookshelf-app-233609" version_id: "20190306t151610" } type: "gae_app" } timestamp: "2019-03-07T09:52:51.793Z" trace: "projects/python-bookshelf-app-233609/traces/dc2baf75b794faea437c4cf98e3ebb94" }

Any idea what I could be doing wrong? Or how to fix it? It works fine on my local machine, I have set the authorized domains and Authorized redirect URIs properly (localhost and full domain, with https and http) as said in the bookshelves tutorial.

gcloud.exceptions.Forbidden when attempting to access app @ localhost:8080

I have followed all of the instructions in this tutorial for running the Bookshelf app with NoSQL.

Getting to the end and attempting to access http://localhost:8080, I get a gcloud.exceptions.Forbidden exception.

Here is the traceback

Traceback (most recent call last): File "C:\Users\Jonathon\Documents\GitHub\getting-started-python\2-structured-data\env\lib\site-packages\flask\app.py", line 1836, in __call__ return self.wsgi_app(environ, start_response) File "C:\Users\Jonathon\Documents\GitHub\getting-started-python\2-structured-data\env\lib\site-packages\flask\app.py", line 1820, in wsgi_app response = self.make_response(self.handle_exception(e)) File "C:\Users\Jonathon\Documents\GitHub\getting-started-python\2-structured-data\env\lib\site-packages\flask\app.py", line 1403, in handle_exception reraise(exc_type, exc_value, tb) File "C:\Users\Jonathon\Documents\GitHub\getting-started-python\2-structured-data\env\lib\site-packages\flask\_compat.py", line 33, in reraise raise value File "C:\Users\Jonathon\Documents\GitHub\getting-started-python\2-structured-data\env\lib\site-packages\flask\app.py", line 1817, in wsgi_app response = self.full_dispatch_request() File "C:\Users\Jonathon\Documents\GitHub\getting-started-python\2-structured-data\env\lib\site-packages\flask\app.py", line 1477, in full_dispatch_request rv = self.handle_user_exception(e) File "C:\Users\Jonathon\Documents\GitHub\getting-started-python\2-structured-data\env\lib\site-packages\flask\app.py", line 1381, in handle_user_exception reraise(exc_type, exc_value, tb) File "C:\Users\Jonathon\Documents\GitHub\getting-started-python\2-structured-data\env\lib\site-packages\flask\_compat.py", line 33, in reraise raise value File "C:\Users\Jonathon\Documents\GitHub\getting-started-python\2-structured-data\env\lib\site-packages\flask\app.py", line 1475, in full_dispatch_request rv = self.dispatch_request() File "C:\Users\Jonathon\Documents\GitHub\getting-started-python\2-structured-data\env\lib\site-packages\flask\app.py", line 1461, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "C:\Users\Jonathon\Documents\GitHub\getting-started-python\2-structured-data\bookshelf\crud.py", line 29, in list books, next_page_token = get_model().list(cursor=token) File "C:\Users\Jonathon\Documents\GitHub\getting-started-python\2-structured-data\bookshelf\model_datastore.py", line 56, in list entities, more_results, cursor = it.next_page() File "C:\Users\Jonathon\Documents\GitHub\getting-started-python\2-structured-data\env\lib\site-packages\gcloud\datastore\query.py", line 424, in next_page transaction_id=transaction and transaction.id, File "C:\Users\Jonathon\Documents\GitHub\getting-started-python\2-structured-data\env\lib\site-packages\gcloud\datastore\connection.py", line 275, in run_query _datastore_pb2.RunQueryResponse) File "C:\Users\Jonathon\Documents\GitHub\getting-started-python\2-structured-data\env\lib\site-packages\gcloud\datastore\connection.py", line 121, in _rpc data=request_pb.SerializeToString()) File "C:\Users\Jonathon\Documents\GitHub\getting-started-python\2-structured-data\env\lib\site-packages\gcloud\datastore\connection.py", line 98, in _request raise make_exception(headers, error_status.message, use_json=False) gcloud.exceptions.Forbidden: 403 Not authorized.

Local mysql server database initialization

DATA_BACKEND = 'cloudsql'
SQLALCHEMY_DATABASE_URI =
'mysql+pymysql://root:[email protected]/mydata'

run local python main.py
http request gives this:

sqlalchemy.exc.ProgrammingError
ProgrammingError: (pymysql.err.ProgrammingError) (1146, u"Table 'mydata.books' doesn't exist") [SQL: u'SELECT books.id AS books_id, books.title AS books_title, books.author AS books_author, books.publishedDate AS books_publishedDate, books.imageUrl AS books_imageUrl, books.description AS books_description, books.createdBy AS books_createdBy, books.createdById AS books_createdById \nFROM books ORDER BY books.title \n LIMIT %(param_1)s, %(param_2)s'] [parameters: {u'param_1': 0, u'param_2': 10}]

How to init database?

bookshelf error on App Engine: "ImportError: cannot import name 'secure_filename' from 'werkzeug'"

Manifests in App Engine by showing:

502 Bad Gateway
nginx

Look in the logs, to see the whole traceback:

Traceback (most recent call last):
File "/env/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker worker.init_process()
File "/env/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 104, in init_process super(ThreadWorker, self).init_process()
File "/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process self.load_wsgi()
File "/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi self.wsgi = self.app.wsgi()
File "/env/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi self.callable = self.load()
File "/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load return self.load_wsgiapp()
File "/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp return util.import_app(self.app_uri)
File "/env/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app import(module)
File "/srv/main.py", line 22, in import storage
File "/srv/storage.py", line 23, in from werkzeug import secure_filename ImportError: cannot import name 'secure_filename' from 'werkzeug' (/env/lib/python3.7/site-packages/werkzeug/init.py)

The Fix seems to be to replace line 23 in storage.py:

from werkzeug import secure_filename

with:

from werkzeug.utils import secure_filename

I've already tested the fix. I'm going to propose a PR.

Cannot Authenticate Cloud SQL proxy

While I see a few issues related to sql connection, I do not see anything matching this scenario._

Currently following the App Engine Flexible Bookshelf Tutorial.
Upon reaching the step "Creating the Database Tables":
The client application fails, unable to make a connection through the proxy.

First Step: I checked the threads on #129 #92 and #126 to make sure I was configuring and authenticating as documented.

The error logged in the proxy service :

Response: {
  "error" : "invalid_grant"
}

Implemented the use cases that fit my needs:

side note: when using setting file path for credential file in CLI, the user is not informed if there is an issue with the file path, file name, or reading the file. I raise this because I do not know if the the launch script is able to locate the cred file since it does not throw a warning if there is an error if it fails to do so.

Abandoning the table creation script python bookshelf/model_cloudsql.py
attempted to access the proxy via mysql directly
mysql --host 127.0.0.1 --user root --password
same error message on proxy as before.
MySQL error:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0

I have placed the issue here because I am following the tutorial and configuring a directed.

Cannot upload image

Hello there,

I'm following the Getting Started -> bookshelf App and I made sure that I have setup the Pre-reqs like - configuring billing, creating app engine, creating a Firestore, the app is running both deployed and in development mode but is there some API being out of date here?
https://gothic-span-272921.uc.r.appspot.com/

2020-05-25 04:04:19 default[20200524t205909]  Traceback (most recent call last):    File "/env/lib/python3.7/site-packages/flask/app.py", line 2447, in wsgi_app      response = self.full_dispatch_reques
t()    File "/env/lib/python3.7/site-packages/flask/app.py", line 1952, in full_dispatch_request      rv = self.handle_user_exception(e)    File "/env/lib/python3.7/site-packages/flask/app.py", line 182
1, in handle_user_exception      reraise(exc_type, exc_value, tb)    File "/env/lib/python3.7/site-packages/flask/_compat.py", line 39, in reraise      raise value    File "/env/lib/python3.7/site-packa
ges/flask/app.py", line 1950, in full_dispatch_request      rv = self.dispatch_request()    File "/env/lib/python3.7/site-packages/flask/app.py", line 1936, in dispatch_request      return self.view_fun
ctions[rule.endpoint](**req.view_args)    File "/srv/main.py", line 85, in add      image_url = upload_image_file(request.files.get('image'))    File "/srv/main.py", line 37, in upload_image_file      i
mg.content_type    File "/srv/storage.py", line 65, in upload_file      content_type=content_type)    File "/env/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 1363, in upload_from_stri
ng      predefined_acl=predefined_acl,    File "/env/lib/python3.7/site-packages/google/cloud/storage/blob.py", line 1267, in upload_from_file      _raise_from_invalid_response(exc)    File "/env/lib/py
thon3.7/site-packages/google/cloud/storage/blob.py", line 2156, in _raise_from_invalid_response      raise exceptions.from_http_status(response.status_code, message, response=response)  google.api_core.
exceptions.NotFound: 404 POST https://storage.googleapis.com/upload/storage/v1/b/gothic-span-272921_bucket/o?uploadType=multipart: ('Request failed with status code', 404, 'Expected one of', <HTTPStatus
.OK: 200>)

Import error on deploy only: No module named google.appengine.api

I've been following the tutorial, in particular section 6-pubsub. I have the project working locally just fine, but when I try to deploy, I get a timeout. See the stacktrace from the logs below. The import error is:

ImportError: No module named 'google.appengine.api'

and it occurs when I try to make a new logging Client. I've seen the same issue in another project when I try to make a new pubsub Client.

2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  |   File "/home/vmagent/app/main.py", line 19, in <module>
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  |     app = bookshelf.create_app(config)
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  |   File "/home/vmagent/app/bookshelf/__init__.py", line 40, in create_app
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  |     client = google.cloud.logging.Client(app.config['PROJECT_ID'])
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  |   File "/env/lib/python3.4/site-packages/google/cloud/client.py", line 186, in __init__
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  |     Client.__init__(self, credentials=credentials, http=http)
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  |   File "/env/lib/python3.4/site-packages/google/cloud/client.py", line 122, in __init__
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  |     credentials = get_credentials()
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  |   File "/env/lib/python3.4/site-packages/google/cloud/credentials.py", line 87, in get_credentials
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  |     return client.GoogleCredentials.get_application_default()
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  |   File "/env/lib/python3.4/site-packages/oauth2client/client.py", line 1288, in get_application_default
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  |     return GoogleCredentials._get_implicit_credentials()
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  |   File "/env/lib/python3.4/site-packages/oauth2client/client.py", line 1273, in _get_implicit_credentials
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  |     credentials = checker()
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  |   File "/env/lib/python3.4/site-packages/oauth2client/client.py", line 1191, in _implicit_credentials_from_gae
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  |     return _get_application_default_credential_GAE()
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  |   File "/env/lib/python3.4/site-packages/oauth2client/client.py", line 1450, in _get_application_default_credential_GAE
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  |     from oauth2client.contrib.appengine import AppAssertionCredentials
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  |   File "/env/lib/python3.4/site-packages/oauth2client/contrib/appengine.py", line 27, in <module>
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  |     from google.appengine.api import app_identity
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 worker.1  | ImportError: No module named 'google.appengine.api'
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 system    | worker.1 stopped (rc=1)
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 system    | sending SIGTERM to monitor.1 (pid 8)
2016-11-02 17:02:18 worker[20161102t123058]  17:02:18 system    | monitor.1 stopped (rc=-15)

How to deploy a python function using gcloud

I want to deploy a python function using the gcloud command. The function trigger is Firestore Document Update.
The document I'm observing in my Firestore Database is: "user_collection/mike"
I'm having problem with the --trigger-resource, when executing the command I get this ERROR:
/user_collection/mike expected to match template projects/{project}/databases/{database}/documents/{document=**}
When i get info for other functions deployed through the Console the resource looks like this:
projects/my-project/databases/(default)/documents/user_collection/jane
What for should I replace the "(default)" part for my trigger to work?
I tried replacing it with "firestore", the function will deploy, but won't trigger.
Tried: --trigger-resource=user_collection/mike but give me the template error.

Best Regards
Edgard

Folder column in the README is all 404's

Thanks for building this repo! I got here while googling how to work with logging using GCP and just noticed that all the links under the Folder column in the table are 404's.

I'd be happy to make a PR to fix but don't know where the content lives (or if it even still exists in this repo)?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.