Skip to content

Commit

Permalink
Use request library to try to improve charts issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bobf committed Jan 14, 2020
1 parent a1908c5 commit 2a2e18f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
1 change: 1 addition & 0 deletions app/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ flask-socketio = "*"
werkzeug = "*"
eventlet = "*"
gunicorn = "*"
requests = "*"

[requires]
python_version = "3.7"
45 changes: 23 additions & 22 deletions app/Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from flask import Flask, render_template, request, send_from_directory, jsonify
from flask_socketio import SocketIO, emit
import requests

from skep.json import DelegatingJSONEncoder

Expand Down Expand Up @@ -57,19 +58,16 @@ def handle_init():
@socketio.on('chart_request')
def handle_chart_request(params):
params['sid'] = request.sid
charts_request = Request(
urllib.parse.urljoin(os.environ['SKEP_CHARTS_URL'], 'chart'),
data=json.dumps(params).encode('utf8'),
headers={'Content-Type': 'application/json'}
)

url = urllib.parse.urljoin(os.environ['SKEP_CHARTS_URL'], 'chart')
data = json.dumps(params).encode('utf8')
headers={'Content-Type': 'application/json'}

log('chart_request [{type}] for [sid: {sid}] [{url}]',
dict(type=params['chartType'],
sid=request.sid,
url=charts_request.full_url))
dict(type=params['chartType'], sid=request.sid, url=url))

try:
response = urllib.request.urlopen(charts_request)
response = requests.post(url, data=data, headers=headers)
except urllib.error.HTTPError as e:
log('chart_request:failure [{url}] [{headers}] [{url}] [{status} {reason}]'.format(
url=e.url,
Expand Down

0 comments on commit 2a2e18f

Please sign in to comment.