Commit ddd45d37 by Matthew Harrigan

Some bytes issues

parent a5e76b21
...@@ -208,7 +208,7 @@ class PDBFixer(object): ...@@ -208,7 +208,7 @@ class PDBFixer(object):
self.source = url self.source = url
file = urlopen(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. # 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') lines = contents.split('\n')
file.close() file.close()
structure = PdbStructure(lines) structure = PdbStructure(lines)
......
...@@ -29,7 +29,7 @@ def loadImageFile(name): ...@@ -29,7 +29,7 @@ def loadImageFile(name):
if name not in cachedImages: if name not in cachedImages:
imagePath = os.path.join(os.path.dirname(__file__), 'images') imagePath = os.path.join(os.path.dirname(__file__), 'images')
file = os.path.join(imagePath, name) file = os.path.join(imagePath, name)
cachedImages[name] = open(file).read() cachedImages[name] = open(file, 'rb').read()
return cachedImages[name] return cachedImages[name]
def controlsCallback(parameters, handler): def controlsCallback(parameters, handler):
...@@ -61,8 +61,15 @@ def startPageCallback(parameters, handler): ...@@ -61,8 +61,15 @@ def startPageCallback(parameters, handler):
id = parameters.getfirst('pdbid') id = parameters.getfirst('pdbid')
try: try:
fixer = PDBFixer(pdbid=id) fixer = PDBFixer(pdbid=id)
except: except Exception as e:
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")) 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() displayDeleteChainsPage()
def deleteChainsPageCallback(parameters, handler): def deleteChainsPageCallback(parameters, handler):
......
...@@ -46,7 +46,7 @@ class _Handler(BaseHTTPRequestHandler): ...@@ -46,7 +46,7 @@ class _Handler(BaseHTTPRequestHandler):
self.send_header("Content-type", type) self.send_header("Content-type", type)
self.send_header("Content-length", str(len(response))) self.send_header("Content-length", str(len(response)))
self.end_headers() self.end_headers()
if sys.version_info.major > 2: if sys.version_info.major > 2 and isinstance(response, str):
response = bytes(response, 'UTF-8') response = bytes(response, 'UTF-8')
self.wfile.write(response) 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