i have a problem when i try to execute my script.py througth appengine just with the library "from google.cloud import bigquery", i try some solutions but i have not had a success way, i show you the scripts which i use to execute this script.
This is my script:
import json
import datetime
import webapp2
from google.cloud import bigquery
from google.appengine.ext import vendor
vendor.add('lib')
filename = "example.json"
def date_format(time):
if time.find(".") != -1:
time = time[:time.find(".")]
date = datetime.datetime.strptime(time,"%Y-%m-%d %H:%M:%S")
return date.strftime("%Y%m%d")
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
with open(filename) as file:
array = []
jsonData = json.load(file)
d = str(date_format(jsonData['e']))
self.response.write('Hello AppEngine from script! :: '+d)
client = bigquery.Client()
QUERY = (
'SELECT field FROM `table` WHERE date='+d+' LIMIT 10'
)
query_job = client.query(QUERY)
rows = query_job.result()
for row in rows:
print(row.field)
app = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
This is my app.yaml:
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: main.app
This is my requirements.txt:
google-api-python-client
google-cloud
I have a lib directory with the bigquery library: google_cloud_bigquery-1.24.0.dist-info. and others libraries with google_cloud
I dont know if my code is correct, because i have saw some solutions but anything helpme to run script with appengine.
i hope you can help me please.
This is the script with python 3
import google.cloud.bigquery as bigquery
# [START gae_python37_app]
from flask import Flask
from google.appengine.ext import vendor
vendor.add('lib')
# If `entrypoint` is not defined in app.yaml, App Engine will look for an app
# called `app` in `main.py`.
app = Flask(__name__)
@app.route('/')
def hello():
"""Return a friendly HTTP greeting."""
client = bigquery.Client()
QUERY = (
'SELECT ev FROM `table` WHERE f="20200201" LIMIT 10'
)
query_job = client.query(QUERY)
rows = query_job.result()
for row in rows:
return row.ev
if __name__ == '__main__':
# This is used when running locally only. When deploying to Google App
# Engine, a webserver process such as Gunicorn will serve the app. This
# can be configured by adding an `entrypoint` to app.yaml.
app.run(host='127.0.0.1', port=8080, debug=True)
# [END gae_python37_app]
You are using App Engine Standard's Python 2.7 runtime. This runtime does not allow you to specify dependencies with a requirements.txt
file.
Instead, you should follow this guide to vendor any dependencies like google-cloud-bigquery
along with your application: https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27
You may need to remove any existing lib
directory entirely and start again.
Also, note that the google-cloud
package is deprecated, you should not use it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.