Skip to content

Commit

Permalink
Fix for GAE and requests compatibility issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ayip001 committed Dec 19, 2017
1 parent 4fdd83d commit 9779534
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ deps:
# for local development environment
$(VENV_DIR)/bin/pip install -Ur $(REQ_DIR)$(REQ_DEV)
$(NODE_PKGMGR) $(NODE_DIR) install
# Patch requests for GAE
patch -p0 < requests-models-py.patch

server:
$(VENV_DIR)/bin/python $(SERVER_DIR)$(SERVER)
Expand Down
21 changes: 21 additions & 0 deletions requests-models-py.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--- src/venv/lib/python3.6/site-packages/requests/models.py 2017-12-19 05:12:08.387025356 -0800
+++ src/lib/requests/models.py 2017-12-19 05:21:08.333796614 -0800
@@ -654,8 +654,16 @@
# Special case for urllib3.
if hasattr(self.raw, 'stream'):
try:
- for chunk in self.raw.stream(chunk_size, decode_content=True):
- yield chunk
+ # Special case for Google App Engine
+ if isinstance(self.raw._original_response._method, int):
+ while True:
+ chunk = self.raw.read(chunk_size, decode_content=True)
+ if not chunk:
+ break
+ yield chunk
+ else:
+ for chunk in self.raw.stream(chunk_size, decode_content=True):
+ yield chunk
except ProtocolError as e:
raise ChunkedEncodingError(e)
except DecodeError as e:
1 change: 1 addition & 0 deletions src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Flask==0.12.2
flask-restful
google-cloud-datastore
requests==2.8.1
7 changes: 4 additions & 3 deletions src/server/api/posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ def get(self):
class PostAPI(Resource):
def get(self, title):
query = QueryHelper()
query.add_filter('title', '=', title)
result = list(query.fetch())
fetched = query.fetch()
result = list(
post for post in fetched if title == post['title'])
if len(result) == 0:
abort(404)
return jsonify(result[0])
Expand All @@ -36,4 +37,4 @@ def get(self, category):
post for post in fetched if category in post['categories'])
if len(result) == 0:
abort(404)
return jsonify(result)
return jsonify(result)

0 comments on commit 9779534

Please sign in to comment.