Commit ddd45d37 by Matthew Harrigan

Some bytes issues

parent a5e76b21
......@@ -208,7 +208,7 @@ class PDBFixer(object):
self.source = url
file = urlopen(url)
# Read contents all at once and split into lines, since urlopen doesn't like it when we read one line at a time over the network.
contents = file.read()
contents = file.read().decode('utf-8')
lines = contents.split('\n')
file.close()
structure = PdbStructure(lines)
......
......@@ -29,7 +29,7 @@ def loadImageFile(name):
if name not in cachedImages:
imagePath = os.path.join(os.path.dirname(__file__), 'images')
file = os.path.join(imagePath, name)
cachedImages[name] = open(file).read()
cachedImages[name] = open(file, 'rb').read()
return cachedImages[name]
def controlsCallback(parameters, handler):
......@@ -61,8 +61,15 @@ def startPageCallback(parameters, handler):
id = parameters.getfirst('pdbid')
try:
fixer = PDBFixer(pdbid=id)
except:
handler.sendResponse(header+"Unable to download the PDB file. This may indicate an invalid PDB identifier, or an error in network connectivity."+loadHtmlFile("error.html"))
except Exception as e:
import traceback
print(traceback.format_exc())
handler.sendResponse(
header + "<p>Unable to download the PDB file. " +
"This may indicate an invalid PDB identifier, " +
"or an error in network connectivity.</p>" +
"<p>{}</p>".format(e) +
loadHtmlFile("error.html"))
displayDeleteChainsPage()
def deleteChainsPageCallback(parameters, handler):
......
......@@ -46,7 +46,7 @@ class _Handler(BaseHTTPRequestHandler):
self.send_header("Content-type", type)
self.send_header("Content-length", str(len(response)))
self.end_headers()
if sys.version_info.major > 2:
if sys.version_info.major > 2 and isinstance(response, str):
response = bytes(response, 'UTF-8')
self.wfile.write(response)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment