From 9f76147dd7555ab1a4c5373c4c5f6e28194b6f9e Mon Sep 17 00:00:00 2001 From: Roman Chyla Date: Thu, 12 Dec 2019 15:21:43 -0500 Subject: [PATCH] Establish a new connection every time talking to orcid enpoint (for exchanging code for token) --- orcid_service/views.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/orcid_service/views.py b/orcid_service/views.py index 2670b4e..41e0e7f 100644 --- a/orcid_service/views.py +++ b/orcid_service/views.py @@ -9,6 +9,7 @@ import logging import pytz import adsmutils +import requests bp = Blueprint('orcid', __name__) @@ -27,7 +28,11 @@ def get_access_token(): 'grant_type': 'authorization_code' } #print current_app.config['ORCID_OAUTH_ENDPOINT'], data, headers - r = current_app.client.post(current_app.config['ORCID_OAUTH_ENDPOINT'], data=data, headers=headers) + + # do not use connection pool, always establish a new connection to the orcid remote server + # we were having issue with dropped connectins mid-stream and this request is not idempotent + # therefore we can't retry + r = requests.post(current_app.config['ORCID_OAUTH_ENDPOINT'], data=data, headers=headers) if r.status_code != 200: logging.error('For ORCID code {}, there was an error getting the token from the ORCID API.'. format(payload['code'][0])) @@ -611,4 +616,4 @@ def find_record(work): 'putcode': putcode, 'source': sources } - } \ No newline at end of file + }