Skip to content

Commit 77355ae

Browse files
committed
requests samples work in 2.7 and 3.7 (gcloud deploy app app3.yaml for the Python 3.7 version)
1 parent 4767c57 commit 77355ae

5 files changed

Lines changed: 80 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
runtime: python27
2+
api_version: 1
3+
threadsafe: yes
4+
5+
handlers:
6+
- url: .*
7+
script: main.app
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
runtime: python37
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from google.appengine.ext import vendor
16+
17+
# Add any libraries installed in the "lib" folder.
18+
vendor.add('lib')
19+
20+
import requests
21+
import requests_toolbelt.adapters.appengine
22+
23+
# Use the App Engine Requests adapter. This makes sure that Requests uses
24+
# URLFetch.
25+
requests_toolbelt.adapters.appengine.monkeypatch()
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START app]
16+
import logging
17+
18+
from flask import Flask
19+
20+
# [START imports]
21+
import requests
22+
# [END imports]
23+
24+
app = Flask(__name__)
25+
26+
27+
@app.route('/')
28+
def index():
29+
# [START requests_get]
30+
url = 'http://www.google.com/humans.txt'
31+
response = requests.get(url)
32+
response.raise_for_status()
33+
return response.text
34+
# [END requests_get]
35+
36+
37+
@app.errorhandler(500)
38+
def server_error(e):
39+
logging.exception('An error occurred during a request.')
40+
return """
41+
An internal error occurred: <pre>{}</pre>
42+
See logs for full stacktrace.
43+
""".format(e), 500
44+
# [END app]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Flask==1.1.1
2+
requests==2.22.0
3+
requests-toolbelt==0.9.1

0 commit comments

Comments
 (0)