fixed octopart fetch for server encoding issues
This commit is contained in:
+10
-9
@@ -1,6 +1,7 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import json, urllib.parse, urllib.request
|
import json
|
||||||
|
import requests
|
||||||
import sqlalchemy
|
import sqlalchemy
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from sqlalchemy.sql import select
|
from sqlalchemy.sql import select
|
||||||
@@ -64,7 +65,7 @@ def serveImage(img):
|
|||||||
img_io.seek(0)
|
img_io.seek(0)
|
||||||
return send_file(img_io, mimetype='image/png')
|
return send_file(img_io, mimetype='image/png')
|
||||||
|
|
||||||
@app.route('/parts', strict_slashes=False)
|
@app.route('/parts', strict_slashes=True)
|
||||||
def index():
|
def index():
|
||||||
return render_template('partsearch.html', containers=getContainers())
|
return render_template('partsearch.html', containers=getContainers())
|
||||||
|
|
||||||
@@ -297,13 +298,13 @@ def deleteLocation(locationID):
|
|||||||
def fetchOctopartSnippet(searchTerm):
|
def fetchOctopartSnippet(searchTerm):
|
||||||
if octopartURL == '':
|
if octopartURL == '':
|
||||||
return '{"result":"octopart integration not enabled"}'
|
return '{"result":"octopart integration not enabled"}'
|
||||||
args = [
|
args = {
|
||||||
('q', searchTerm),
|
'q': searchTerm,
|
||||||
('start', 0),
|
'start': '0',
|
||||||
('limit', 1)
|
'limit': 1
|
||||||
]
|
}
|
||||||
data = urllib.request.urlopen(octopartURL + '&' + urllib.parse.urlencode(args)).read()
|
data = requests.get(octopartURL, params=args)
|
||||||
search_response = json.loads(data)
|
search_response = json.loads(data.text)
|
||||||
|
|
||||||
result = '{"result":"no results. sorry :(("}'
|
result = '{"result":"no results. sorry :(("}'
|
||||||
if search_response['hits']>0:
|
if search_response['hits']>0:
|
||||||
|
|||||||
Reference in New Issue
Block a user