diff --git a/parts/server.py b/parts/server.py index f8f6f01..54614cd 100644 --- a/parts/server.py +++ b/parts/server.py @@ -1,6 +1,7 @@ import os import re -import json, urllib.parse, urllib.request +import json +import requests import sqlalchemy from functools import wraps from sqlalchemy.sql import select @@ -64,7 +65,7 @@ def serveImage(img): img_io.seek(0) return send_file(img_io, mimetype='image/png') -@app.route('/parts', strict_slashes=False) +@app.route('/parts', strict_slashes=True) def index(): return render_template('partsearch.html', containers=getContainers()) @@ -297,13 +298,13 @@ def deleteLocation(locationID): def fetchOctopartSnippet(searchTerm): if octopartURL == '': return '{"result":"octopart integration not enabled"}' - args = [ - ('q', searchTerm), - ('start', 0), - ('limit', 1) - ] - data = urllib.request.urlopen(octopartURL + '&' + urllib.parse.urlencode(args)).read() - search_response = json.loads(data) + args = { + 'q': searchTerm, + 'start': '0', + 'limit': 1 + } + data = requests.get(octopartURL, params=args) + search_response = json.loads(data.text) result = '{"result":"no results. sorry :(("}' if search_response['hits']>0: