fixed octopart fetch for server encoding issues

pull/3/head
Marek Baczynski 6 years ago
parent 2a8b1f50f4
commit 38c22af31f

@ -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:

Loading…
Cancel
Save