File tree Expand file tree Collapse file tree
appengine/standard/migration/urlfetch/requests Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ runtime : python27
2+ api_version : 1
3+ threadsafe : yes
4+
5+ handlers :
6+ - url : .*
7+ script : main.app
Original file line number Diff line number Diff line change 1+ runtime : python37
Original file line number Diff line number Diff line change 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 ()
Original file line number Diff line number Diff line change 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]
Original file line number Diff line number Diff line change 1+ Flask == 1.1.1
2+ requests == 2.22.0
3+ requests-toolbelt == 0.9.1
You can’t perform that action at this time.
0 commit comments